+2007-03-21 Øyvind Kolås <pippin@gimp.org>
+
+ Reindented all of the code using uncrustify.
+
2007-03-21 Øyvind Kolås <pippin@gimp.org>
* configure.ac: Make force the value of shrext to either .dll or .so
2007-01-06 Michael Schumacher <schumaml@cvs.gnome.org>
- This change makes babl buildable on Windows.
+ This change makes babl buildable on Windows.
* configure.ac: Add a check for function dlopen and disabled
static libs by default. Check for gettimeofday by using
#include <stdarg.h>
-static int
+static int
each_babl_component_destroy (Babl *babl,
void *data)
{
{
Babl *babl;
- babl = babl_malloc (sizeof (BablComponent) + strlen (name) + 1);
- babl->instance.name = (char *) babl + sizeof (BablComponent);
+ babl = babl_malloc (sizeof (BablComponent) + strlen (name) + 1);
+ babl->instance.name = (char *) babl + sizeof (BablComponent);
strcpy (babl->instance.name, name);
babl->class_type = BABL_COMPONENT;
{
va_list varg;
Babl *babl;
- int id = 0;
- int luma = 0;
- int chroma = 0;
- int alpha = 0;
- const char *arg=(char*)first_arg;
+ int id = 0;
+ int luma = 0;
+ int chroma = 0;
+ int alpha = 0;
+ const char *arg = (char *) first_arg;
va_start (varg, first_arg);
-
+
while (1)
{
arg = va_arg (varg, char *);
if (!arg)
break;
-
+
if (BABL_IS_BABL (arg))
{
#ifdef BABL_LOG
- Babl *babl = (Babl*) arg;
+ Babl *babl = (Babl *) arg;
babl_log ("%s unexpected", babl_class_name (babl->class_type));
#endif
}
{
id = va_arg (varg, int);
}
-
+
else if (!strcmp (arg, "luma"))
{
luma = 1;
}
-
+
else if (!strcmp (arg, "chroma"))
{
chroma = 1;
{
alpha = 1;
}
-
+
else
{
babl_fatal ("unhandled argument '%s' for format '%s'", arg, first_arg);
}
}
-
- va_end (varg);
+
+ va_end (varg);
babl = component_new (first_arg, id, luma, chroma, alpha);
- {
+ {
Babl *ret = babl_db_insert (db, babl);
- if (ret!=babl)
- babl_free (babl);
+ if (ret != babl)
+ babl_free (babl);
return ret;
}
}
}
static Babl *
-conversion_new (const char *name,
- int id,
- Babl *source,
- Babl *destination,
- BablFuncLinear linear,
- BablFuncPlane plane,
- BablFuncPlanar planar)
+conversion_new (const char *name,
+ int id,
+ Babl *source,
+ Babl *destination,
+ BablFuncLinear linear,
+ BablFuncPlane plane,
+ BablFuncPlanar planar)
{
Babl *babl = NULL;
babl_assert (source->class_type ==
destination->class_type);
- babl = babl_malloc (sizeof (BablConversion) + strlen (name) + 1);
- babl->instance.name = (char *)babl + sizeof (BablConversion);
- strcpy(babl->instance.name, name);
+ babl = babl_malloc (sizeof (BablConversion) + strlen (name) + 1);
+ babl->instance.name = (char *) babl + sizeof (BablConversion);
+ strcpy (babl->instance.name, name);
if (linear)
{
- babl->class_type = BABL_CONVERSION_LINEAR;
+ babl->class_type = BABL_CONVERSION_LINEAR;
babl->conversion.function.linear = linear;
}
else if (plane)
{
- babl->class_type = BABL_CONVERSION_PLANE;
+ babl->class_type = BABL_CONVERSION_PLANE;
babl->conversion.function.plane = plane;
}
else if (planar)
{
- babl->class_type = BABL_CONVERSION_PLANAR;
+ babl->class_type = BABL_CONVERSION_PLANAR;
babl->conversion.function.planar = planar;
}
switch (source->class_type)
babl_class_name (source->class_type));
}
break;
+
case BABL_MODEL:
if (plane)
{
babl_class_name (source->class_type));
}
break;
+
case BABL_FORMAT:
break;
+
default:
- babl_fatal ("%s unexpected", babl_class_name (babl->class_type));
+ babl_fatal ("%s unexpected", babl_class_name (babl->class_type));
break;
}
babl->conversion.processings = 0;
if (babl->class_type == BABL_CONVERSION_LINEAR &&
- BABL(babl->conversion.source)->class_type == BABL_MODEL)
+ BABL (babl->conversion.source)->class_type == BABL_MODEL)
{
- Babl *src_format=NULL;
- Babl *dst_format=NULL;
- if (BABL(babl->conversion.source) == babl_model_id (BABL_RGBA))
- {
- src_format = babl_format_id (BABL_RGBA_DOUBLE);
- dst_format = babl_format_with_model_as_type (
- BABL(babl->conversion.destination),
- babl_type_id (BABL_DOUBLE));
- }
- else if (BABL(babl->conversion.destination) == babl_model_id (BABL_RGBA))
- {
- src_format = babl_format_with_model_as_type (
- BABL(babl->conversion.source),
- babl_type_id (BABL_DOUBLE));
- dst_format = babl_format_id (BABL_RGBA_DOUBLE);
- }
- else
- {
- babl_fatal ("neither source nor destination model is RGBA (requirement might be temporary)");
- }
- babl_conversion_new (
- src_format,
- dst_format,
- "linear", linear,
- NULL);
- babl->conversion.error = 0.0;
+ Babl *src_format = NULL;
+ Babl *dst_format = NULL;
+ if (BABL (babl->conversion.source) == babl_model_id (BABL_RGBA))
+ {
+ src_format = babl_format_id (BABL_RGBA_DOUBLE);
+ dst_format = babl_format_with_model_as_type (
+ BABL (babl->conversion.destination),
+ babl_type_id (BABL_DOUBLE));
+ }
+ else if (BABL (babl->conversion.destination) == babl_model_id (BABL_RGBA))
+ {
+ src_format = babl_format_with_model_as_type (
+ BABL (babl->conversion.source),
+ babl_type_id (BABL_DOUBLE));
+ dst_format = babl_format_id (BABL_RGBA_DOUBLE);
+ }
+ else
+ {
+ babl_fatal ("neither source nor destination model is RGBA (requirement might be temporary)");
+ }
+ babl_conversion_new (
+ src_format,
+ dst_format,
+ "linear", linear,
+ NULL);
+ babl->conversion.error = 0.0;
}
return babl;
}
-static char buf[512]="";
+static char buf[512] = "";
static char *
create_name (Babl *source, Babl *destination, int type)
{
-
if (babl_extender ())
{
- snprintf (buf, 512-1, "%s : %s%s to %s",
- BABL(babl_extender())->instance.name,
- type == BABL_CONVERSION_LINEAR?"":
- type == BABL_CONVERSION_PLANE?"plane ":
- type == BABL_CONVERSION_PLANAR?"planar ":"Eeeek! ",
- source->instance.name,
- destination->instance.name);
- buf[511]='\0';
+ snprintf (buf, 512 - 1, "%s : %s%s to %s",
+ BABL (babl_extender ())->instance.name,
+ type == BABL_CONVERSION_LINEAR ? "" :
+ type == BABL_CONVERSION_PLANE ? "plane " :
+ type == BABL_CONVERSION_PLANAR ? "planar " : "Eeeek! ",
+ source->instance.name,
+ destination->instance.name);
+ buf[511] = '\0';
}
else
{
- snprintf (buf, 512-1, "%s %s to %s",
- type == BABL_CONVERSION_LINEAR?"":
- type == BABL_CONVERSION_PLANE?"plane ":
- type == BABL_CONVERSION_PLANAR?"planar ":"Eeeek! ",
- source->instance.name,
- destination->instance.name);
- buf[511]='\0';
+ snprintf (buf, 512 - 1, "%s %s to %s",
+ type == BABL_CONVERSION_LINEAR ? "" :
+ type == BABL_CONVERSION_PLANE ? "plane " :
+ type == BABL_CONVERSION_PLANAR ? "planar " : "Eeeek! ",
+ source->instance.name,
+ destination->instance.name);
+ buf[511] = '\0';
}
return buf;
}
babl_conversion_new (void *first_arg,
...)
{
- va_list varg;
- Babl *babl;
+ va_list varg;
+ Babl *babl;
- int id = 0;
- BablFuncLinear linear = NULL;
- BablFuncPlane plane = NULL;
- BablFuncPlanar planar = NULL;
- int type = 0;
- int got_func = 0;
- const char *arg = first_arg;
+ int id = 0;
+ BablFuncLinear linear = NULL;
+ BablFuncPlane plane = NULL;
+ BablFuncPlanar planar = NULL;
+ int type = 0;
+ int got_func = 0;
+ const char *arg = first_arg;
- Babl *source;
- Babl *destination;
+ Babl *source;
+ Babl *destination;
va_start (varg, first_arg);
- source = (Babl*) arg;
- destination = va_arg (varg, Babl*);
- arg = va_arg (varg, char *);
+ source = (Babl *) arg;
+ destination = va_arg (varg, Babl *);
+ arg = va_arg (varg, char *);
- assert (BABL_IS_BABL(source));
- assert (BABL_IS_BABL(destination));
+ assert (BABL_IS_BABL (source));
+ assert (BABL_IS_BABL (destination));
while (arg)
{
-
if (!strcmp (arg, "id"))
{
id = va_arg (varg, int);
arg = va_arg (varg, char *);
}
- va_end (varg);
+ va_end (varg);
assert (source);
assert (destination);
type = BABL_CONVERSION_PLANAR;
}
babl = conversion_new (create_name (source, destination, type),
- id, source, destination, linear, plane, planar);
+ id, source, destination, linear, plane, planar);
{
Babl *ret = babl_db_insert (db, babl);
- if (ret!=babl)
- babl_free (babl);
+ if (ret != babl)
+ babl_free (babl);
else
- babl_add_ptr_to_list ((void ***)((Babl*)&(source->type.from)), babl);
+ babl_add_ptr_to_list ((void ***) ((Babl *) &(source->type.from)), babl);
return ret;
}
int dst_pitch,
long n)
{
- return conversion->function.plane (source, destination,
+ return conversion->function.plane (source, destination,
src_pitch, dst_pitch,
n);
}
long n)
{
#ifdef USE_ALLOCA
- char **src_data = alloca (sizeof (void*) * source->components);
- char **dst_data = alloca (sizeof (void*) * destination->components);
+ char **src_data = alloca (sizeof (void *) * source->components);
+ char **dst_data = alloca (sizeof (void *) * destination->components);
#else
- char *src_data[BABL_MAX_COMPONENTS];
- char *dst_data[BABL_MAX_COMPONENTS];
+ char *src_data[BABL_MAX_COMPONENTS];
+ char *dst_data[BABL_MAX_COMPONENTS];
#endif
- memcpy (src_data, source->data, sizeof (void*) * source->components);
- memcpy (dst_data, destination->data, sizeof (void*) * destination->components);
+ memcpy (src_data, source->data, sizeof (void *) * source->components);
+ memcpy (dst_data, destination->data, sizeof (void *) * destination->components);
return conversion->function.planar (source->components,
src_data,
char *destination,
long n)
{
- BablConversion *conversion = (BablConversion*) babl;
+ BablConversion *conversion = (BablConversion *) babl;
babl_assert (BABL_IS_BABL (conversion));
- switch (BABL(conversion)->class_type)
- {
- case BABL_CONVERSION_PLANE:
+ switch (BABL (conversion)->class_type)
+ {
+ case BABL_CONVERSION_PLANE:
{
- void *src_data = NULL;
- void *dst_data = NULL;
+ void *src_data = NULL;
+ void *dst_data = NULL;
int src_pitch = 0;
int dst_pitch = 0;
- if (BABL_IS_BABL(source))
+ if (BABL_IS_BABL (source))
{
BablImage *img;
- img = (BablImage*)source;
+ img = (BablImage *) source;
src_data = img->data[0];
src_pitch = img->pitch[0];
}
- if (BABL_IS_BABL(destination))
+ if (BABL_IS_BABL (destination))
{
- BablImage *img = (BablImage*)destination;
+ BablImage *img = (BablImage *) destination;
dst_data = img->data[0];
dst_pitch = img->pitch[0];
}
if (!src_data)
- src_data=source;
+ src_data = source;
if (!src_pitch)
- src_pitch=BABL(conversion->source)->type.bits/8;
+ src_pitch = BABL (conversion->source)->type.bits / 8;
if (!dst_data)
- dst_data=destination;
+ dst_data = destination;
if (!dst_pitch)
- dst_pitch=BABL(conversion->destination)->type.bits/8;
+ dst_pitch = BABL (conversion->destination)->type.bits / 8;
babl_conversion_plane_process (conversion,
- src_data, dst_data,
+ src_data, dst_data,
src_pitch, dst_pitch,
n);
}
- break;
- case BABL_CONVERSION_PLANAR:
- babl_assert (BABL_IS_BABL (source));
- babl_assert (BABL_IS_BABL (destination));
-
- babl_conversion_planar_process ( conversion,
- (BablImage*) source,
- (BablImage*) destination,
- n);
- break;
- case BABL_CONVERSION_LINEAR:
- /* the assertions relied on a babl_malloc structure
- *
- * babl_assert (!BABL_IS_BABL (source));
- babl_assert (!BABL_IS_BABL (destination));*/
-
- babl_conversion_linear_process (conversion,
- source,
- destination,
- n);
- break;
-
- default:
- babl_log ("args=(%s, %p, %p, %li) unhandled conversion type: %s",
- conversion->instance.name, source, destination, n,
- babl_class_name (conversion->instance.class_type));
- return 0;
- break;
- }
+ break;
+
+ case BABL_CONVERSION_PLANAR:
+ babl_assert (BABL_IS_BABL (source));
+ babl_assert (BABL_IS_BABL (destination));
+
+ babl_conversion_planar_process (conversion,
+ (BablImage *) source,
+ (BablImage *) destination,
+ n);
+ break;
- conversion->processings ++;
+ case BABL_CONVERSION_LINEAR:
+ /* the assertions relied on a babl_malloc structure
+ *
+ * babl_assert (!BABL_IS_BABL (source));
+ babl_assert (!BABL_IS_BABL (destination));*/
+
+ babl_conversion_linear_process (conversion,
+ source,
+ destination,
+ n);
+ break;
+
+ default:
+ babl_log ("args=(%s, %p, %p, %li) unhandled conversion type: %s",
+ conversion->instance.name, source, destination, n,
+ babl_class_name (conversion->instance.class_type));
+ return 0;
+ break;
+ }
+
+ conversion->processings++;
conversion->pixels += n;
return n;
}
-#define test_pixels 512
+#define test_pixels 512
static double *
test_create (void)
test = babl_malloc (sizeof (double) * test_pixels * 4);
for (i = 0; i < test_pixels * 4; i++)
- test [i] = (double) random () / RAND_MAX;
+ test [i] = (double) random () / RAND_MAX;
return test;
}
{
if (!conversion)
return 100000000L;
- if (conversion->error==-1.0)
+ if (conversion->error == -1.0)
babl_conversion_error (conversion);
return conversion->cost;
}
Babl *fmt_source;
Babl *fmt_destination;
- Babl *fmt_rgba_double = fmt_rgba_double = babl_format_new (
- babl_model ("RGBA"),
- babl_type ("double"),
- babl_component ("R"),
- babl_component ("G"),
- babl_component ("B"),
- babl_component ("A"),
- NULL);
-
- double error = 0.0;
- long ticks_start = 0;
- long ticks_end = 0;
-
- double *test;
- void *source;
- void *destination;
- double *destination_rgba_double;
- void *ref_destination;
- double *ref_destination_rgba_double;
-
- Babl *fish_rgba_to_source;
- Babl *fish_reference;
- Babl *fish_destination_to_rgba;
+ Babl *fmt_rgba_double = babl_format_new (babl_model ("RGBA"),
+ babl_type ("double"),
+ babl_component ("R"),
+ babl_component ("G"),
+ babl_component ("B"),
+ babl_component ("A"),
+ NULL);
+
+ double error = 0.0;
+ long ticks_start = 0;
+ long ticks_end = 0;
+
+ double *test;
+ void *source;
+ void *destination;
+ double *destination_rgba_double;
+ void *ref_destination;
+ double *ref_destination_rgba_double;
+
+ Babl *fish_rgba_to_source;
+ Babl *fish_reference;
+ Babl *fish_destination_to_rgba;
if (!conversion)
return 0.0;
- fmt_source = BABL(conversion->source);
- fmt_destination = BABL(conversion->destination);
+ fmt_source = BABL (conversion->source);
+ fmt_destination = BABL (conversion->destination);
fish_rgba_to_source = babl_fish_reference (fmt_rgba_double, fmt_source);
fish_reference = babl_fish_reference (fmt_source, fmt_destination);
return 0.0;
}
- if (!(fmt_source->instance.id != BABL_RGBA &&
- fmt_destination->instance.id != BABL_RGBA &&
- fmt_source->instance.id != BABL_DOUBLE &&
- fmt_destination->instance.id != BABL_DOUBLE &&
- fmt_source->class_type == BABL_FORMAT &&
- fmt_destination->class_type == BABL_FORMAT))
+ if (!(fmt_source->instance.id != BABL_RGBA &&
+ fmt_destination->instance.id != BABL_RGBA &&
+ fmt_source->instance.id != BABL_DOUBLE &&
+ fmt_destination->instance.id != BABL_DOUBLE &&
+ fmt_source->class_type == BABL_FORMAT &&
+ fmt_destination->class_type == BABL_FORMAT))
{
conversion->error = 0.000042;
}
return conversion->error;
}
- test=test_create ();
+ test = test_create ();
- source = babl_calloc (test_pixels, fmt_source->format.bytes_per_pixel);
- destination = babl_calloc (test_pixels, fmt_destination->format.bytes_per_pixel);
- ref_destination = babl_calloc (test_pixels, fmt_destination->format.bytes_per_pixel);
+ source = babl_calloc (test_pixels, fmt_source->format.bytes_per_pixel);
+ destination = babl_calloc (test_pixels, fmt_destination->format.bytes_per_pixel);
+ ref_destination = babl_calloc (test_pixels, fmt_destination->format.bytes_per_pixel);
destination_rgba_double = babl_calloc (test_pixels, fmt_rgba_double->format.bytes_per_pixel);
ref_destination_rgba_double = babl_calloc (test_pixels, fmt_rgba_double->format.bytes_per_pixel);
babl_process (fish_rgba_to_source,
- test, source, test_pixels);
+ test, source, test_pixels);
ticks_start = babl_ticks ();
babl_process (babl_fish_simple (conversion),
- source, destination, test_pixels);
+ source, destination, test_pixels);
ticks_end = babl_ticks ();
babl_process (fish_reference,
- source, ref_destination, test_pixels);
+ source, ref_destination, test_pixels);
babl_process (fish_destination_to_rgba,
- ref_destination, ref_destination_rgba_double, test_pixels);
+ ref_destination, ref_destination_rgba_double, test_pixels);
babl_process (fish_destination_to_rgba,
- destination, destination_rgba_double, test_pixels);
+ destination, destination_rgba_double, test_pixels);
error = babl_rel_avg_error (destination_rgba_double,
ref_destination_rgba_double,
- test_pixels*4);
+ test_pixels * 4);
fish_rgba_to_source->fish.processings--;
fish_reference->fish.processings--;
- fish_destination_to_rgba->fish.processings-=2;
+ fish_destination_to_rgba->fish.processings -= 2;
- fish_rgba_to_source->fish.pixels -= test_pixels;
- fish_reference->fish.pixels -= test_pixels;
+ fish_rgba_to_source->fish.pixels -= test_pixels;
+ fish_reference->fish.pixels -= test_pixels;
fish_destination_to_rgba->fish.pixels -= 2 * test_pixels;
babl_free (test);
conversion->error = error;
- conversion->cost = (ticks_end-ticks_start)*10+1;
+ conversion->cost = (ticks_end - ticks_start) * 10 + 1;
return error;
}
/* babl - dynamically extendable universal pixel conversion library.
-
+
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
if (src_pitch == 64 &&
dst_pitch == 64)
{
- memcpy (dst, src, n/8);
+ memcpy (dst, src, n / 8);
return n;
}
while (n--)
{
(*(double *) dst) = (*(double *) src);
- dst += dst_pitch;
- src += src_pitch;
+ dst += dst_pitch;
+ src += src_pitch;
}
return n;
}
/*
-static long
-copy_strip_1 (int src_bands,
+ static long
+ copy_strip_1 (int src_bands,
char **src,
int *src_pitch,
int dst_bands,
char **dst,
int *dst_pitch,
long n)
-{
- BABL_PLANAR_SANITY
- while (n--)
+ {
+ BABL_PLANAR_SANITY
+ while (n--)
{
int i;
foo = *(double *) src[i];
else
foo = 1.0;
- *(double*)dst[i] = foo;
+ *(double*)dst[i] = foo;
}
BABL_PLANAR_STEP
}
- return n;
-}
+ return n;
+ }
-*/
+ */
static long
rgba_to_rgba (char *src,
char *dst,
{
babl_type_new (
"double",
- "id", BABL_DOUBLE,
- "bits", 64,
+ "id", BABL_DOUBLE,
+ "bits", 64,
NULL);
babl_component_new (
NULL);
babl_component_new (
- "G",
- "id", BABL_GREEN,
- "luma",
- "chroma",
- NULL);
-
+ "G",
+ "id", BABL_GREEN,
+ "luma",
+ "chroma",
+ NULL);
+
babl_component_new (
- "B",
- "id", BABL_BLUE,
- "luma",
- "chroma",
- NULL);
+ "B",
+ "id", BABL_BLUE,
+ "luma",
+ "chroma",
+ NULL);
babl_component_new (
- "A",
- "id", BABL_ALPHA,
- "alpha",
- NULL);
+ "A",
+ "id", BABL_ALPHA,
+ "alpha",
+ NULL);
babl_component_new (
- "PAD",
- "id", BABL_PADDING,
- NULL);
+ "PAD",
+ "id", BABL_PADDING,
+ NULL);
babl_model_new (
"id", BABL_RGBA,
NULL);
/*
- babl_conversion_new (
- babl_model_id (BABL_RGBA),
- babl_model_id (BABL_RGBA),
- "planar", copy_strip_1,
- NULL
- );
- */
+ babl_conversion_new (
+ babl_model_id (BABL_RGBA),
+ babl_model_id (BABL_RGBA),
+ "planar", copy_strip_1,
+ NULL
+ );
+ */
babl_conversion_new (
babl_type_id (BABL_DOUBLE),
babl_type_id (BABL_DOUBLE),
- "plane", convert_double_double,
+ "plane", convert_double_double,
NULL
);
babl_conversion_new (
babl_model_id (BABL_RGBA),
babl_model_id (BABL_RGBA),
- "linear", rgba_to_rgba,
+ "linear", rgba_to_rgba,
NULL
);
}
#include <string.h>
#include "babl-internal.h"
-#define HASH_TABLE_SIZE 128
-#define DB_INITIAL_SIZE 16
-#define DB_INCREMENT_SIZE 16
+#define HASH_TABLE_SIZE 128
+#define DB_INITIAL_SIZE 16
+#define DB_INCREMENT_SIZE 16
static inline int hash (const char *str)
{
int i = 1;
while (*str)
- ret = (ret + ( i++ * (*str ++ & 31 ))) % (HASH_TABLE_SIZE-1);
+ ret = (ret + (i++ * (*str++ & 31))) % (HASH_TABLE_SIZE - 1);
return ret;
}
-typedef struct _BablDb {
+typedef struct _BablDb
+{
Babl *hash [HASH_TABLE_SIZE];
int size;
int count;
BablDb *
-babl_db_init(void)
+babl_db_init (void)
{
BablDb *db = babl_calloc (sizeof (BablDb), 1);
+
db->size = DB_INITIAL_SIZE;
db->count = 0;
db->items = NULL;
if (db->size)
{
- db->items = babl_calloc (sizeof (BablInstance*), db->size);
+ db->items = babl_calloc (sizeof (BablInstance *), db->size);
}
return db;
}
collision = babl_db_exist (db, item->instance.id, item->instance.name);
if (collision)
- return collision;
+ return collision;
if (db->count + 1 > db->size) /* must reallocate storage */
{
Babl **new_items;
- new_items = babl_realloc (db->items, (db->size + DB_INCREMENT_SIZE) * sizeof (BablInstance*));
+ new_items = babl_realloc (db->items, (db->size + DB_INCREMENT_SIZE) * sizeof (BablInstance *));
babl_assert (new_items);
db->items = new_items;
/* null out the currently unused portions of memory */
- memset (db->items + db->size, 0, DB_INCREMENT_SIZE * sizeof (Babl*));
+ memset (db->items + db->size, 0, DB_INCREMENT_SIZE * sizeof (Babl *));
db->size += DB_INCREMENT_SIZE;
}
if (db->hash[key] == NULL)
db->hash[key] = item;
}
- db->items[db->count++]=item;
+ db->items[db->count++] = item;
/* this point all registered items pass through, a nice
- * place to brand them with where the item came from. */
+ * place to brand them with where the item came from. */
item->instance.creator = babl_extender ();
return item;
}
void
-babl_db_each (BablDb *db,
- BablEachFunction each_fun,
- void *user_data)
+babl_db_each (BablDb *db,
+ BablEachFunction each_fun,
+ void *user_data)
{
int i;
- for (i=0; i< db->count; i++)
+ for (i = 0; i < db->count; i++)
{
if (db->items[i])
{
- if (each_fun ((Babl*) db->items[i], user_data))
+ if (each_fun ((Babl *) db->items[i], user_data))
break;
}
}
typedef struct BablDbExistData
{
- int id;
- const char *name;
- Babl *ret;
+ int id;
+ const char *name;
+ Babl *ret;
} BablDbExistData;
-static int
+static int
babl_db_each_exist (Babl *babl,
void *void_data)
{
if (data->id && data->id == babl->instance.id)
{
- data->ret = babl;
- return 1; /* stop iterating */
+ data->ret = babl;
+ return 1; /* stop iterating */
}
else if (data->name && !strcmp (babl->instance.name, data->name))
{
return 0; /* continue iterating */
}
-Babl *
+Babl *
babl_db_exist (BablDb *db,
int id,
const char *name)
Babl *ret = NULL;
if (name)
- ret = db->hash[hash (name)];
+ ret = db->hash[hash (name)];
if (ret &&
name[0] == ret->instance.name[0] &&
!strcmp (name, ret->instance.name))
- return ret;
+ return ret;
{
BablDbExistData data;
- data.id = id;
+ data.id = id;
data.name = name;
- data.ret = NULL;
+ data.ret = NULL;
babl_db_each (db, babl_db_each_exist, &data);
#ifdef HAVE_CONFIG_H
#include "config.h"
#else
-#define BABL_PATH PREFIX "/babl-0.0"
-#define BABL_PATH_SEPERATOR "/"
-#define BABL_LIST_SEPERATOR ':'
+#define BABL_PATH PREFIX "/babl-0.0"
+#define BABL_PATH_SEPERATOR "/"
+#define BABL_LIST_SEPERATOR ':'
#endif
-#define BABL_INIT_HOOK init_hook();
-#define BABL_DESTROY_HOOK destroy_hook();
+#define BABL_INIT_HOOK init_hook ();
+#define BABL_DESTROY_HOOK destroy_hook ();
#ifdef BABL_DYNAMIC_EXTENSIONS
- /* must be defined before inclusion of babl-internal.h */
+/* must be defined before inclusion of babl-internal.h */
#undef BABL_INIT_HOOK
-#define BABL_INIT_HOOK init_hook();dynamic_init_hook();
+#define BABL_INIT_HOOK init_hook (); dynamic_init_hook ();
#endif
#include "babl-internal.h"
static Babl *
extension_new (const char *path,
void *dl_handle,
- void (*destroy) (void))
+ void (*destroy)(void))
{
Babl *babl;
- babl = babl_malloc (sizeof (BablExtension) + strlen (path) + 1);
- babl->instance.name = (char *) babl + sizeof (BablExtension);
+ babl = babl_malloc (sizeof (BablExtension) + strlen (path) + 1);
+ babl->instance.name = (char *) babl + sizeof (BablExtension);
strcpy (babl->instance.name, path);
- babl->instance.id = 0;
- babl->class_type = BABL_EXTENSION;
- babl->extension.dl_handle = dl_handle;
- babl->extension.destroy = destroy;
+ babl->instance.id = 0;
+ babl->class_type = BABL_EXTENSION;
+ babl->extension.dl_handle = dl_handle;
+ babl->extension.destroy = destroy;
return babl;
}
babl_extension_base (void)
{
Babl *babl;
- void *dl_handle = NULL;
- void (*destroy) (void) = NULL;
+ void *dl_handle = NULL;
- if (!db)
+ void (*destroy)(void) = NULL;
+
+ if (!db)
db = babl_db_init ();
babl = extension_new ("BablBase",
dl_handle,
destroy);
babl_set_extender (babl);
- {
+ {
Babl *ret = babl_db_insert (db, babl);
- if (ret!=babl)
- babl_free (babl);
+ if (ret != babl)
+ babl_free (babl);
else
- babl_base_init ();
+ babl_base_init ();
babl = ret;
}
babl_set_extender (NULL);
destroy_hook (void)
{
babl_free (babl_quiet);
- babl_quiet=NULL;
+ babl_quiet = NULL;
}
#ifdef BABL_DYNAMIC_EXTENSIONS
#ifdef HAVE_DLFCN_H
#include <dlfcn.h>
-#define HLIB void *
+#define HLIB void *
#endif
#ifndef RTLD_NOW
-#define RTLD_NOW 0
+#define RTLD_NOW 0
#endif
-#ifdef WIN32
-#define WIN32_LEAN_AND_MEAN
+#ifdef WIN32
+#define WIN32_LEAN_AND_MEAN
#include <windows.h>
-#define HLIB HINSTANCE
+#define HLIB HINSTANCE
-#define dlopen(a, b) LoadLibrary(a)
-#define dlsym(l, s) GetProcAddress(l, s)
-#define dlclose(l) FreeLibrary(l)
-#define dlerror() GetLastError()
-#endif
+#define dlopen(a, b) LoadLibrary (a)
+#define dlsym(l, s) GetProcAddress (l, s)
+#define dlclose(l) FreeLibrary (l)
+#define dlerror() GetLastError ()
+#endif
static Babl *
load_failed (Babl *babl)
static Babl *
babl_extension_load (const char *path)
{
- Babl *babl = NULL;
+ Babl *babl = NULL;
/* do the actual loading thing */
- HLIB dl_handle = NULL;
- int (*init) (void) = NULL;
- void (*destroy) (void) = NULL;
-
+ HLIB dl_handle = NULL;
+
+ int (*init)(void) = NULL;
+ void (*destroy)(void) = NULL;
+
dl_handle = dlopen (path, RTLD_NOW);
if (!dl_handle)
{
babl_log ("dlopen() failed:\n\t%s", dlerror ());
return load_failed (babl);
}
- init = dlsym (dl_handle, "init");
+ init = dlsym (dl_handle, "init");
if (!init)
{
babl_log ("\n\tint babl_extension_init() function not found in extenstion '%s'", path);
return load_failed (babl);
}
-
+
destroy = dlsym (dl_handle, "destroy");
- babl = extension_new (path,
- dl_handle,
- destroy);
+ babl = extension_new (path,
+ dl_handle,
+ destroy);
babl_set_extender (babl);
- if(init())
+ if (init ())
{
babl_log ("babl_extension_init() in extension '%s' failed (return!=0)", path);
return load_failed (babl);
static void
babl_extension_load_dir (const char *base_path)
{
- DIR *dir;
+ DIR *dir;
if ((dir = opendir (base_path)))
- {
- struct dirent *dentry;
-
- while ((dentry = readdir (dir)) != NULL)
- {
- if (dentry->d_name[0] != '.')
- {
- char *path = NULL;
- struct stat st;
- char *extension;
-
- path = babl_strcat (path, base_path);
- path = babl_strcat (path, BABL_PATH_SEPERATOR);
- path = babl_strcat (path, dentry->d_name);
-
- stat (path, &st);
-
- if ((extension = strrchr (dentry->d_name, '.')) !=NULL &&
- !strcmp (extension, SHREXT))
- {
- babl_extension_load (path);
- }
+ {
+ struct dirent *dentry;
+
+ while ((dentry = readdir (dir)) != NULL)
+ {
+ if (dentry->d_name[0] != '.')
+ {
+ char *path = NULL;
+ struct stat st;
+ char *extension;
+
+ path = babl_strcat (path, base_path);
+ path = babl_strcat (path, BABL_PATH_SEPERATOR);
+ path = babl_strcat (path, dentry->d_name);
+
+ stat (path, &st);
- babl_free (path);
- }
+ if ((extension = strrchr (dentry->d_name, '.')) != NULL &&
+ !strcmp (extension, SHREXT))
+ {
+ babl_extension_load (path);
+ }
- }
- closedir (dir);
- }
+ babl_free (path);
+ }
+ }
+ closedir (dir);
+ }
}
static const char *
babl_dir_list (void)
{
const char *ret;
-
+
ret = getenv ("BABL_PATH");
if (!ret)
ret = BABL_PATH;
dst = NULL;
- src=path;
+ src = path;
- while(*src)
+ while (*src)
{
switch (*src)
{
case '~':
dst = babl_strcat (dst, getenv ("HOME"));
break;
+
default:
- {
- char tmp[2]="?";
- tmp[0]=*src;
- dst = babl_strcat (dst, tmp);
- }
+ {
+ char tmp[2] = "?";
+ tmp[0] = *src;
+ dst = babl_strcat (dst, tmp);
+ }
}
src++;
}
static void
babl_extension_load_dir_list (const char *dir_list)
{
- int eos = 0;
+ int eos = 0;
const char *src;
char *path, *dst;
path = babl_strdup (dir_list);
- src = dir_list;
- dst = path;
+ src = dir_list;
+ dst = path;
while (!eos)
{
switch (*src)
{
- case '\0':
- eos=1;
- case BABL_LIST_SEPERATOR:
- {
- char *expanded_path = expand_path (path);
- babl_extension_load_dir (expanded_path);
- babl_free (expanded_path);
- }
- dst=path;
- src++;
- *dst = '\0';
- break;
- default:
- *(dst++) = *(src++);
- *dst = '\0';
- break;
+ case '\0':
+ eos = 1;
+
+ case BABL_LIST_SEPERATOR:
+ {
+ char *expanded_path = expand_path (path);
+ babl_extension_load_dir (expanded_path);
+ babl_free (expanded_path);
+ }
+ dst = path;
+ src++;
+ *dst = '\0';
+ break;
+
+ default:
+ *(dst++) = *(src++);
+ *dst = '\0';
+ break;
}
}
babl_free (path);
#endif
-static int
+static int
each_babl_extension_destroy (Babl *babl,
void *data)
{
if (babl->extension.destroy)
- babl->extension.destroy();
+ babl->extension.destroy ();
if (babl->extension.dl_handle)
dlclose (babl->extension.dl_handle);
static double legal_error (void)
{
- static double error=0.0;
- const char *env;
+ static double error = 0.0;
+ const char *env;
if (error != 0.0)
return error;
- env=getenv ("BABL_ERROR");
+ env = getenv ("BABL_ERROR");
if (env)
error = atof (env);
- else
+ else
error = 0.000001;
return error;
}
static int max_path_length (void)
{
- static int max_length=0;
+ static int max_length = 0;
const char *env;
if (max_length != 0)
return max_length;
- env=getenv ("BABL_PATH_LENGTH");
+ env = getenv ("BABL_PATH_LENGTH");
if (env)
max_length = atoi (env);
else
return max_length;
}
-typedef struct BablChainContext {
- Babl *from;
- Babl *to;
+typedef struct BablChainContext
+{
+ Babl *from;
+ Babl *to;
double *best_cost;
double *best_loss;
double *best_error;
BablConversion **chain;
- int *conversions;
+ int *conversions;
BablConversion **temp_chain;
- int temp_conversions;
+ int temp_conversions;
- int max_conversions;
+ int max_conversions;
} BablChainContext;
static int
void *userdata);
static int
-get_conversion_chain (Babl *from,
- Babl *to,
- double *best_cost,
- double *best_loss,
- double *best_error,
- BablConversion **chain,
- int *conversions,
- BablConversion **temp_chain,
- int temp_conversions,
- int max_conversions)
+get_conversion_chain (Babl *from,
+ Babl *to,
+ double *best_cost,
+ double *best_loss,
+ double *best_error,
+ BablConversion **chain,
+ int *conversions,
+ BablConversion **temp_chain,
+ int temp_conversions,
+ int max_conversions)
{
BablChainContext context;
- if (temp_conversions>=max_conversions)
+ if (temp_conversions >= max_conversions)
return 0;
if (temp_conversions == 0)
{
/* chain initialization */
- *conversions = 0;
- *best_cost = 200000.0;
- *best_loss = 200000.0;
- *best_error = 200000.0;
- chain[0] = NULL;
+ *conversions = 0;
+ *best_cost = 200000.0;
+ *best_loss = 200000.0;
+ *best_error = 200000.0;
+ chain[0] = NULL;
temp_chain[0] = NULL;
/* Bail out if requesting something stupid (to and from same format, an
*/
if (from == to)
- return 0;
+ return 0;
}
/* copy parameters to stack */
- context.from = from;
- context.to = to;
+ context.from = from;
+ context.to = to;
- context.best_cost = best_cost;
- context.best_loss = best_loss;
- context.best_error = best_error;
- context.chain = chain;
- context.conversions = conversions;
+ context.best_cost = best_cost;
+ context.best_loss = best_loss;
+ context.best_error = best_error;
+ context.chain = chain;
+ context.conversions = conversions;
context.temp_chain = temp_chain;
context.temp_conversions = temp_conversions;
- context.max_conversions = max_conversions;
+ context.max_conversions = max_conversions;
if (temp_conversions == 0)
{
- temp_chain[temp_conversions]=NULL;
+ temp_chain[temp_conversions] = NULL;
babl_assert (from);
babl_assert (from->class_type == BABL_FORMAT);
if (!from->format.from)
return 0;
- babl_list_each ((void**) from->format.from,
- chain_gen_each,
- &context);
+ babl_list_each ((void **) from->format.from,
+ chain_gen_each,
+ &context);
}
else
{
- if (BABL(temp_chain[temp_conversions-1]) &&
- BABL(temp_chain[temp_conversions-1]->destination)->
+ if (BABL (temp_chain[temp_conversions - 1]) &&
+ BABL (temp_chain[temp_conversions - 1]->destination)->
format.from)
- babl_list_each (
- (void **)
- BABL(temp_chain[temp_conversions-1]->destination)->
- format.from,
- chain_gen_each,
- &context);
+ babl_list_each (
+ (void **)
+ BABL (temp_chain[temp_conversions - 1]->destination)->
+ format.from,
+ chain_gen_each,
+ &context);
}
return 0;
Babl *fmt)
{
int i;
- for (i=0;i<conversions;i++)
- if (BABL(chain[i]->destination)==fmt ||
- BABL(chain[i]->source)==fmt)
+
+ for (i = 0; i < conversions; i++)
+ if (BABL (chain[i]->destination) == fmt ||
+ BABL (chain[i]->source) == fmt)
{
return 1;
}
BablChainContext *c = userdata;
/* fill in the conversion for the chain index we are at */
- c->temp_chain[c->temp_conversions] = (BablConversion*)babl;
+ c->temp_chain[c->temp_conversions] = (BablConversion *) babl;
- {
- if ((BABL(babl->conversion.destination) == c->to) )
- {
- /* a candidate path has been found */
+ {
+ if ((BABL (babl->conversion.destination) == c->to))
+ {
+ /* a candidate path has been found */
- double temp_cost = 0.0;
- double temp_error = 1.0;
- int i;
+ double temp_cost = 0.0;
+ double temp_error = 1.0;
+ int i;
- for (i=0; i < c->temp_conversions+1; i++)
- {
- temp_error *= (1.0+babl_conversion_error (c->temp_chain[i]));
- temp_cost += babl_conversion_cost (c->temp_chain[i]);
- }
+ for (i = 0; i < c->temp_conversions + 1; i++)
+ {
+ temp_error *= (1.0 + babl_conversion_error (c->temp_chain[i]));
+ temp_cost += babl_conversion_cost (c->temp_chain[i]);
+ }
- if (temp_cost < *c->best_cost &&
- temp_error - 1.0 <= legal_error() && /* this check before the next; which does a more accurate
+ if (temp_cost < *c->best_cost &&
+ temp_error - 1.0 <= legal_error () && /* this check before the next; which does a more accurate
measurement of the error */
- (temp_error=chain_error (c->from, c->to, c->temp_chain, c->temp_conversions+1)) <= legal_error()
- )
- {
- int i;
-
- *c->best_cost = temp_cost;
- *c->best_error = temp_error;
- *c->conversions = c->temp_conversions + 1;
-
- /* copy from temp chain to best chain */
- for (i = 0; i < *c->conversions; i++)
- c->chain[i] = c->temp_chain[i];
- }
- }
- else if (babl->conversion.source != babl->conversion.destination &&
- !chain_contains_fmt (c->temp_chain,
- c->temp_conversions,
- BABL(babl->conversion.destination)))
- {
- /* try to add another conversion level in chain,.. */
- get_conversion_chain (c->from, /* irrelevant when recalled */
- c->to,
+ (temp_error = chain_error (c->from, c->to, c->temp_chain, c->temp_conversions + 1)) <= legal_error ()
+ )
+ {
+ int i;
+
+ *c->best_cost = temp_cost;
+ *c->best_error = temp_error;
+ *c->conversions = c->temp_conversions + 1;
+
+ /* copy from temp chain to best chain */
+ for (i = 0; i < *c->conversions; i++)
+ c->chain[i] = c->temp_chain[i];
+ }
+ }
+ else if (babl->conversion.source != babl->conversion.destination &&
+ !chain_contains_fmt (c->temp_chain,
+ c->temp_conversions,
+ BABL (babl->conversion.destination)))
+ {
+ /* try to add another conversion level in chain,.. */
+ get_conversion_chain (c->from, /* irrelevant when recalled */
+ c->to,
- c->best_cost,
- c->best_loss,
- c->best_error,
- c->chain,
- c->conversions,
+ c->best_cost,
+ c->best_loss,
+ c->best_error,
+ c->chain,
+ c->conversions,
- c->temp_chain,
- c->temp_conversions + 1,
+ c->temp_chain,
+ c->temp_conversions + 1,
- c->max_conversions);
- }
- }
+ c->max_conversions);
+ }
+ }
return 0;
}
assert_conversion_find (void *source,
void *destination)
{
- int i=0;
+ int i = 0;
Babl **conversion;
- conversion = (void*)BABL(source)->type.from;
+ conversion = (void *) BABL (source)->type.from;
while (conversion && conversion[i])
{
if (conversion[i]->conversion.destination == destination)
- return (Babl*)conversion[i];
+ return (Babl *) conversion[i];
i++;
}
babl_fatal ("failed, aborting");
{
/* fish names are intentionally kept short */
snprintf (buf, 1024, "%s %p %p", "",
- source, destination);
+ source, destination);
return buf;
}
Babl *
-babl_fish_path (Babl *source,
- Babl *destination)
+babl_fish_path (Babl *source,
+ Babl *destination)
{
- Babl *babl = NULL;
- char *name = create_name (source, destination, 1);
+ Babl *babl = NULL;
+ char *name = create_name (source, destination, 1);
BablConversion *temp_chain[BABL_HARD_MAX_PATH_LENGTH];
babl_assert (BABL_IS_BABL (source));
babl_assert (source->class_type == BABL_FORMAT);
babl_assert (destination->class_type == BABL_FORMAT);
- babl = babl_calloc (1, sizeof (BablFishPath) +
- strlen (name) + 1);
- babl->class_type = BABL_FISH_PATH;
- babl->instance.id = 0;
- babl->instance.name = ((char*)babl) + sizeof(BablFishPath);
+ babl = babl_calloc (1, sizeof (BablFishPath) +
+ strlen (name) + 1);
+ babl->class_type = BABL_FISH_PATH;
+ babl->instance.id = 0;
+ babl->instance.name = ((char *) babl) + sizeof (BablFishPath);
strcpy (babl->instance.name, name);
babl->fish.source = source;
babl->fish.destination = destination;
babl->fish.usecs = 0;
babl->fish.error = 200000;
- babl->fish_path.cost = 200000;
- babl->fish_path.loss = 200000;
- babl->fish_path.conversions = 0;
+ babl->fish_path.cost = 200000;
+ babl->fish_path.loss = 200000;
+ babl->fish_path.conversions = 0;
babl->fish_path.conversion[0] = NULL;
babl_assert (source->class_type == BABL_FORMAT);
&babl->fish_path.cost,
&babl->fish_path.loss,
&babl->fish.error,
- (BablConversion**)(babl->fish_path.conversion),
+ (BablConversion **) (babl->fish_path.conversion),
&babl->fish_path.conversions,
temp_chain,
0,
max_path_length ());
- if (babl->fish_path.conversions==0)
+ if (babl->fish_path.conversions == 0)
{
babl_free (babl);
return NULL;
{
Babl *ret = babl_db_insert (babl_fish_db (), babl);
- if (ret!=babl)
- babl_free (babl);
+ if (ret != babl)
+ babl_free (babl);
return ret;
}
}
if (conversions > 2)
bufB = babl_malloc (n * sizeof (double) * 5);
- for (i=0; i<conversions; i++)
+ for (i = 0; i < conversions; i++)
{
- if (i==0 && conversions == 1)
+ if (i == 0 && conversions == 1)
{
- babl_conversion_process ( BABL(chain[i]),
- source, destination, n);
+ babl_conversion_process (BABL (chain[i]),
+ source, destination, n);
}
else if (i == 0)
{
- babl_conversion_process ( BABL(chain[i]),
- source, bufA, n);
+ babl_conversion_process (BABL (chain[i]),
+ source, bufA, n);
}
else if (i % 2 == 0)
{
if (i + 1 == conversions)
{
- babl_conversion_process ( BABL(chain[i]),
- bufB, destination, n);
+ babl_conversion_process (BABL (chain[i]),
+ bufB, destination, n);
}
else
{
- babl_conversion_process ( BABL(chain[i]),
- bufB, bufA, n);
+ babl_conversion_process (BABL (chain[i]),
+ bufB, bufA, n);
}
}
else if (i % 2 == 1)
{
if (i + 1 == conversions)
{
- babl_conversion_process ( BABL(chain[i]),
- bufA, destination, n);
+ babl_conversion_process (BABL (chain[i]),
+ bufA, destination, n);
}
else
{
- babl_conversion_process ( BABL(chain[i]),
- bufA, bufB, n);
+ babl_conversion_process (BABL (chain[i]),
+ bufA, bufB, n);
}
}
}
babl_fish_path_process (Babl *babl,
void *source,
void *destination,
- long n)
+ long n)
{
long ret;
}
-#define test_pixels 128
+#define test_pixels 128
static double *
test_create (void)
test = babl_malloc (sizeof (double) * test_pixels * 4);
for (i = 0; i < test_pixels * 4; i++)
- test [i] = (double) random () / RAND_MAX;
+ test [i] = (double) random () / RAND_MAX;
return test;
}
int conversions)
{
Babl *fmt_rgba_double = babl_format_new (
- babl_model ("RGBA"),
- babl_type ("double"),
- babl_component ("R"),
- babl_component ("G"),
- babl_component ("B"),
- babl_component ("A"),
- NULL);
+ babl_model ("RGBA"),
+ babl_type ("double"),
+ babl_component ("R"),
+ babl_component ("G"),
+ babl_component ("B"),
+ babl_component ("A"),
+ NULL);
- double error = 0.0;
+ double error = 0.0;
- double *test;
- void *source;
- void *destination;
- double *destination_rgba_double;
- void *ref_destination;
- double *ref_destination_rgba_double;
+ double *test;
+ void *source;
+ void *destination;
+ double *destination_rgba_double;
+ void *ref_destination;
+ double *ref_destination_rgba_double;
- Babl *fish_rgba_to_source = babl_fish_reference (fmt_rgba_double, fmt_source);
- Babl *fish_reference = babl_fish_reference (fmt_source, fmt_destination);
- Babl *fish_destination_to_rgba = babl_fish_reference (fmt_destination, fmt_rgba_double);
+ Babl *fish_rgba_to_source = babl_fish_reference (fmt_rgba_double, fmt_source);
+ Babl *fish_reference = babl_fish_reference (fmt_source, fmt_destination);
+ Babl *fish_destination_to_rgba = babl_fish_reference (fmt_destination, fmt_rgba_double);
- test=test_create ();
+ test = test_create ();
- source = babl_calloc (test_pixels, fmt_source->format.bytes_per_pixel);
- destination = babl_calloc (test_pixels, fmt_destination->format.bytes_per_pixel);
- ref_destination = babl_calloc (test_pixels, fmt_destination->format.bytes_per_pixel);
+ source = babl_calloc (test_pixels, fmt_source->format.bytes_per_pixel);
+ destination = babl_calloc (test_pixels, fmt_destination->format.bytes_per_pixel);
+ ref_destination = babl_calloc (test_pixels, fmt_destination->format.bytes_per_pixel);
destination_rgba_double = babl_calloc (test_pixels, fmt_rgba_double->format.bytes_per_pixel);
ref_destination_rgba_double = babl_calloc (test_pixels, fmt_rgba_double->format.bytes_per_pixel);
- /* create sourcebuffer from testbuffer in the correct format */
+ /* create sourcebuffer from testbuffer in the correct format */
babl_process (fish_rgba_to_source,
- test, source, test_pixels);
+ test, source, test_pixels);
/* calculate the reference buffer of how it should be */
babl_process (fish_reference,
- source, ref_destination, test_pixels);
+ source, ref_destination, test_pixels);
/* calculate this chains view of what the result should be */
chain_process (chain, conversions, source, destination, test_pixels);
* for comparison with each other
*/
babl_process (fish_destination_to_rgba,
- ref_destination, ref_destination_rgba_double, test_pixels);
+ ref_destination, ref_destination_rgba_double, test_pixels);
babl_process (fish_destination_to_rgba,
- destination, destination_rgba_double, test_pixels);
+ destination, destination_rgba_double, test_pixels);
error = babl_rel_avg_error (destination_rgba_double,
ref_destination_rgba_double,
- test_pixels*4);
+ test_pixels * 4);
fish_rgba_to_source->fish.processings--;
fish_reference->fish.processings--;
- fish_destination_to_rgba->fish.processings-=2;
+ fish_destination_to_rgba->fish.processings -= 2;
- fish_rgba_to_source->fish.pixels -= test_pixels;
- fish_reference->fish.pixels -= test_pixels;
+ fish_rgba_to_source->fish.pixels -= test_pixels;
+ fish_reference->fish.pixels -= test_pixels;
fish_destination_to_rgba->fish.pixels -= 2 * test_pixels;
babl_free (source);
{
/* fish names are intentionally kept short */
snprintf (buf, 1024, "%s %p %p",
- is_reference?"ref "
- :"",
- source, destination);
+ is_reference ? "ref "
+ : "",
+ source, destination);
return buf;
}
Babl *
-babl_fish_reference (Babl *source,
- Babl *destination)
+babl_fish_reference (Babl *source,
+ Babl *destination)
{
Babl *babl = NULL;
char *name = create_name (source, destination, 1);
babl_assert (source->class_type == BABL_FORMAT);
babl_assert (destination->class_type == BABL_FORMAT);
- babl = babl_malloc (sizeof (BablFishReference) +
- strlen (name) + 1);
- babl->class_type = BABL_FISH_REFERENCE;
- babl->instance.id = 0;
- babl->instance.name = ((char *)babl) + sizeof(BablFishReference);
+ babl = babl_malloc (sizeof (BablFishReference) +
+ strlen (name) + 1);
+ babl->class_type = BABL_FISH_REFERENCE;
+ babl->instance.id = 0;
+ babl->instance.name = ((char *) babl) + sizeof (BablFishReference);
strcpy (babl->instance.name, name);
babl->fish.source = source;
babl->fish.destination = destination;
babl->fish.error = 0.0; /* assuming the provided reference conversions for types
and models are as exact as possible
*/
- {
+ {
Babl *ret = babl_db_insert (babl_fish_db (), babl);
- if (ret!=babl)
- babl_free (babl);
+ if (ret != babl)
+ babl_free (babl);
return ret;
}
}
char *source_double_buf,
int n)
{
- int i;
+ int i;
BablImage *src_img;
BablImage *dst_img;
-
- src_img = (BablImage*) babl_image (
- babl_component_id (BABL_LUMINANCE), NULL, 1, 0, NULL);
- dst_img = (BablImage*) babl_image (
- babl_component_id (BABL_LUMINANCE), NULL, 1, 0, NULL);
-
- dst_img->type[0] = (BablType*) babl_type_id (BABL_DOUBLE);
- dst_img->pitch[0] =
- (dst_img->type[0]->bits/8) * source_fmt->model->components;
+
+ src_img = (BablImage *) babl_image (
+ babl_component_id (BABL_LUMINANCE), NULL, 1, 0, NULL);
+ dst_img = (BablImage *) babl_image (
+ babl_component_id (BABL_LUMINANCE), NULL, 1, 0, NULL);
+
+ dst_img->type[0] = (BablType *) babl_type_id (BABL_DOUBLE);
+ dst_img->pitch[0] =
+ (dst_img->type[0]->bits / 8) * source_fmt->model->components;
dst_img->stride[0] = 0;
src_img->data[0] = source_buf;
- src_img->type[0] = (BablType*) babl_type_id (BABL_DOUBLE);
+ src_img->type[0] = (BablType *) babl_type_id (BABL_DOUBLE);
src_img->pitch[0] = source_fmt->bytes_per_pixel;
src_img->stride[0] = 0;
/* i is source position */
- for (i=0 ; i<source_fmt->components; i++)
+ for (i = 0; i < source_fmt->components; i++)
{
int j;
src_img->type[0] = source_fmt->type[i];
/* j is source position */
- for (j=0;j<source_fmt->model->components;j++)
+ for (j = 0; j < source_fmt->model->components; j++)
{
if (source_fmt->component[i] ==
source_fmt->model->component[j])
{
dst_img->data[0] =
- source_double_buf + (dst_img->type[0]->bits/8) * j;
+ source_double_buf + (dst_img->type[0]->bits / 8) * j;
break;
}
}
babl_process (
- assert_conversion_find (src_img->type[0], dst_img->type[0]),
- src_img, dst_img,
- n);
- src_img->data[0] += src_img->type[0]->bits/8;
+ assert_conversion_find (src_img->type[0], dst_img->type[0]),
+ src_img, dst_img,
+ n);
+ src_img->data[0] += src_img->type[0]->bits / 8;
}
babl_free (src_img);
babl_free (dst_img);
char *destination_buf,
int n)
{
- int i;
+ int i;
BablImage *src_img;
BablImage *dst_img;
- src_img = (BablImage*) babl_image (
- babl_component_id (BABL_LUMINANCE), NULL, 1, 0, NULL);
- dst_img = (BablImage*) babl_image (
- babl_component_id (BABL_LUMINANCE), NULL, 1, 0, NULL);
+ src_img = (BablImage *) babl_image (
+ babl_component_id (BABL_LUMINANCE), NULL, 1, 0, NULL);
+ dst_img = (BablImage *) babl_image (
+ babl_component_id (BABL_LUMINANCE), NULL, 1, 0, NULL);
- src_img->type[0] = (BablType*) babl_type_id (BABL_DOUBLE);
- src_img->pitch[0] = (src_img->type[0]->bits/8) * destination_fmt->model->components;
+ src_img->type[0] = (BablType *) babl_type_id (BABL_DOUBLE);
+ src_img->pitch[0] = (src_img->type[0]->bits / 8) * destination_fmt->model->components;
src_img->stride[0] = 0;
- dst_img->data[0] = destination_buf;
- dst_img->type[0] = (BablType*) babl_type_id (BABL_DOUBLE);
- dst_img->pitch[0] = destination_fmt->bytes_per_pixel;
- dst_img->stride = 0;
+ dst_img->data[0] = destination_buf;
+ dst_img->type[0] = (BablType *) babl_type_id (BABL_DOUBLE);
+ dst_img->pitch[0] = destination_fmt->bytes_per_pixel;
+ dst_img->stride = 0;
- for (i=0 ; i<destination_fmt->components; i++)
+ for (i = 0; i < destination_fmt->components; i++)
{
int j;
dst_img->type[0] = destination_fmt->type[i];
- for (j=0;j<destination_fmt->model->components;j++)
+ for (j = 0; j < destination_fmt->model->components; j++)
{
if (destination_fmt->component[i] ==
destination_fmt->model->component[j])
{
src_img->data[0] =
- destination_double_buf + (src_img->type[0]->bits/8) * j;
+ destination_double_buf + (src_img->type[0]->bits / 8) * j;
break;
}
}
babl_process (
- assert_conversion_find (src_img->type[0], dst_img->type[0]),
- src_img, dst_img,
- n);
- dst_img->data[0] += dst_img->type[0]->bits/8;
+ assert_conversion_find (src_img->type[0], dst_img->type[0]),
+ src_img, dst_img,
+ n);
+ dst_img->data[0] += dst_img->type[0]->bits / 8;
}
babl_free (src_img);
babl_free (dst_img);
process_same_model (Babl *babl,
BablImage *source,
BablImage *destination,
- long n)
+ long n)
{
void *double_buf;
BABL_IS_BABL (destination))
{
babl_log ("args=(%p, %p, %p, %li): trying to handle BablImage (unconfirmed code)",
- babl_fish, source, destination, n);
+ babl_fish, source, destination, n);
}
- double_buf = babl_malloc(sizeof (double) * n *
- BABL(babl->fish.source)->format.model->components);
+ double_buf = babl_malloc (sizeof (double) * n *
+ BABL (babl->fish.source)->format.model->components);
convert_to_double (
- (BablFormat*) BABL(babl->fish.source),
- BABL_IS_BABL(source)?source:NULL,
- BABL_IS_BABL(source)?NULL:(char*)source,
- double_buf,
- n
- );
+ (BablFormat *) BABL (babl->fish.source),
+ BABL_IS_BABL (source) ? source : NULL,
+ BABL_IS_BABL (source) ? NULL : (char *) source,
+ double_buf,
+ n
+ );
convert_from_double (
- (BablFormat*) BABL(babl->fish.destination),
- double_buf,
- BABL_IS_BABL(destination)?destination:NULL,
- BABL_IS_BABL(destination)?NULL:(char*)destination,
- n
- );
+ (BablFormat *) BABL (babl->fish.destination),
+ double_buf,
+ BABL_IS_BABL (destination) ? destination : NULL,
+ BABL_IS_BABL (destination) ? NULL : (char *) destination,
+ n
+ );
babl_free (double_buf);
return 0;
babl_fish_reference_process (Babl *babl,
BablImage *source,
BablImage *destination,
- long n)
+ long n)
{
void *source_double_buf;
void *rgba_double_buf;
Babl *rgba_image;
Babl *destination_image;
- if (BABL(babl->fish.source)->format.model ==
- BABL(babl->fish.destination)->format.model)
- return process_same_model (babl, source, destination, n);
+ if (BABL (babl->fish.source)->format.model ==
+ BABL (babl->fish.destination)->format.model)
+ return process_same_model (babl, source, destination, n);
#if 0
if (BABL_IS_BABL (source) ||
BABL_IS_BABL (destination))
{
babl_log ("args=(%p, %p, %p, %li): trying to handle BablImage (unconfirmed code)",
- babl_fish, source, destination, n);
+ babl_fish, source, destination, n);
}
#endif
- source_double_buf = babl_malloc(sizeof (double) * n *
- BABL(babl->fish.source)->format.model->components);
- rgba_double_buf = babl_malloc(sizeof (double) * n * 4);
- destination_double_buf = babl_malloc(sizeof (double) * n *
- BABL(babl->fish.destination)->format.model->components);
+ source_double_buf = babl_malloc (sizeof (double) * n *
+ BABL (babl->fish.source)->format.model->components);
+ rgba_double_buf = babl_malloc (sizeof (double) * n * 4);
+ destination_double_buf = babl_malloc (sizeof (double) * n *
+ BABL (babl->fish.destination)->format.model->components);
- source_image = babl_image_from_linear (
- source_double_buf,BABL(BABL((babl->fish.source)) -> format.model));
- rgba_image = babl_image_from_linear (
- rgba_double_buf, babl_model_id (BABL_RGBA));
+ source_image = babl_image_from_linear (
+ source_double_buf, BABL (BABL ((babl->fish.source))->format.model));
+ rgba_image = babl_image_from_linear (
+ rgba_double_buf, babl_model_id (BABL_RGBA));
destination_image = babl_image_from_linear (
- destination_double_buf, BABL(BABL((babl->fish.destination))->format.model));
+ destination_double_buf, BABL (BABL ((babl->fish.destination))->format.model));
convert_to_double (
- (BablFormat*) BABL(babl->fish.source),
- NULL,
- (char*)source,
- source_double_buf,
- n
- );
+ (BablFormat *) BABL (babl->fish.source),
+ NULL,
+ (char *) source,
+ source_double_buf,
+ n
+ );
{
Babl *conv =
- assert_conversion_find (
- BABL(babl->fish.source)->format.model,
- babl_model_id (BABL_RGBA)
- );
+ assert_conversion_find (
+ BABL (babl->fish.source)->format.model,
+ babl_model_id (BABL_RGBA)
+ );
if (conv->class_type == BABL_CONVERSION_PLANAR)
{
babl_process (
- conv,
+ conv,
source_image, rgba_image,
n);
}
else if (conv->class_type == BABL_CONVERSION_LINEAR)
{
babl_process (
- conv,
- source_double_buf, rgba_double_buf,
- n);
+ conv,
+ source_double_buf, rgba_double_buf,
+ n);
}
else babl_fatal ("oops");
}
{
Babl *conv =
- assert_conversion_find (
- babl_model_id (BABL_RGBA),
- BABL(babl->fish.destination)->format.model);
+ assert_conversion_find (
+ babl_model_id (BABL_RGBA),
+ BABL (babl->fish.destination)->format.model);
if (conv->class_type == BABL_CONVERSION_PLANAR)
{
babl_process (
- conv,
+ conv,
rgba_image, destination_image,
n);
}
else if (conv->class_type == BABL_CONVERSION_LINEAR)
{
babl_process (
- conv,
+ conv,
rgba_double_buf, destination_double_buf,
n);
}
}
convert_from_double (
- (BablFormat*) BABL(babl->fish.destination),
- destination_double_buf,
- NULL,
- (char*)destination,
- n
- );
+ (BablFormat *) BABL (babl->fish.destination),
+ destination_double_buf,
+ NULL,
+ (char *) destination,
+ n
+ );
babl_free (source_image);
babl_free (rgba_image);
babl_assert (BABL_IS_BABL (conversion));
- name = create_name (conversion);
+ name = create_name (conversion);
- babl = babl_malloc (sizeof (BablFishSimple) +
- strlen (name) + 1);
- babl->class_type = BABL_FISH_SIMPLE;
- babl->instance.id = 0;
- babl->instance.name = ((char *)babl) + sizeof(BablFishSimple);
+ babl = babl_malloc (sizeof (BablFishSimple) +
+ strlen (name) + 1);
+ babl->class_type = BABL_FISH_SIMPLE;
+ babl->instance.id = 0;
+ babl->instance.name = ((char *) babl) + sizeof (BablFishSimple);
strcpy (babl->instance.name, name);
babl->fish.source = conversion->source;
babl->fish.destination = conversion->destination;
- babl->fish.processings = 0;
- babl->fish.pixels = 0;
+ babl->fish.processings = 0;
+ babl->fish.pixels = 0;
babl->fish_simple.conversion = conversion;
- babl->fish.error = 0.0; /* babl fish simple should only be used by bablfish
+ babl->fish.error = 0.0;/* babl fish simple should only be used by bablfish
reference, and babl fish reference only requests clean
conversions */
- {
+ {
Babl *ret = babl_db_insert (babl_fish_db (), babl);
- if (ret!=babl)
- babl_free (babl);
+ if (ret != babl)
+ babl_free (babl);
return ret;
}
}
#include "babl-internal.h"
static FILE *output_file = NULL;
-static int qux=0;
+static int qux = 0;
-static char *utf8_bar[]={" ","·","▁","▂","▃","▄","▅","▆","▇","█"};
+static char *utf8_bar[] = { " ", "·", "▁", "▂", "▃", "▄", "▅", "▆", "▇", "█" };
//static char *utf8_bar[]= {"!","▁","▃","▅","▇","█","!","!","!"};
//static char *utf8_bar[]={"·", "█", "▇", "▆", "▅", "▄", "▃", "▂", "▁", };
//static char *utf8_bar[]={" ","1","2","3","4","5","6","7","8"};
table_destination_each (Babl *babl,
void *userdata)
{
- Babl *source = userdata;
+ Babl *source = userdata;
Babl *destination = babl;
- if ((qux++) % babl_formats_count () == qux/ babl_formats_count ())
- fprintf (output_file, "<td class='cell'> </td>");
+ if ((qux++) % babl_formats_count () == qux / babl_formats_count ())
+ fprintf (output_file, "<td class='cell'> </td>");
else
{
Babl *fish = babl_fish (source, destination);
case BABL_FISH_PATH:
fprintf (output_file, "<td class='cell'%s><a href='javascript:o()'>%s",
- fish->fish.processings > 0 ? " style='background-color: #69f'":"",
- utf8_bar[fish->fish_path.conversions]);
+ fish->fish.processings > 0 ? " style='background-color: #69f'" : "",
+ utf8_bar[fish->fish_path.conversions]);
{
int i;
}
fprintf (output_file, "<table>\n");
- fprintf (output_file, "<tr>");
- fprintf (output_file, "<td><em>conversion</em></td>");
- fprintf (output_file, "<td style='text-align:right'><em>cost</em></td>");
- fprintf (output_file, "<td style='text-align:right'><em>error</em></td>");
- fprintf (output_file, "</tr>");
+ fprintf (output_file, "<tr>");
+ fprintf (output_file, "<td><em>conversion</em></td>");
+ fprintf (output_file, "<td style='text-align:right'><em>cost</em></td>");
+ fprintf (output_file, "<td style='text-align:right'><em>error</em></td>");
+ fprintf (output_file, "</tr>");
- for (i=0; i< fish->fish_path.conversions; i++)
- {
+ for (i = 0; i < fish->fish_path.conversions; i++)
+ {
fprintf (output_file, "<tr>");
- fprintf (output_file, "<td>%s</td>", BABL(fish->fish_path.conversion[i])->instance.name);
- fprintf (output_file, "<td class='r'>%li</td>", babl_conversion_cost (&BABL(fish->fish_path.conversion[i])->conversion));
- fprintf (output_file, "<td class='r'>%e</td>", babl_conversion_error (&BABL(fish->fish_path.conversion[i])->conversion));
+ fprintf (output_file, "<td>%s</td>", BABL (fish->fish_path.conversion[i])->instance.name);
+ fprintf (output_file, "<td class='r'>%li</td>", babl_conversion_cost (&BABL (fish->fish_path.conversion[i])->conversion));
+ fprintf (output_file, "<td class='r'>%e</td>", babl_conversion_error (&BABL (fish->fish_path.conversion[i])->conversion));
fprintf (output_file, "</tr>");
- }
+ }
- fprintf (output_file, "<tr>");
- fprintf (output_file, "<td><em>total</em></td>");
- fprintf (output_file, "<td class='r'><em>%3.0f</em></td>", fish->fish_path.cost);
- fprintf (output_file, "<td class='r'><em>%e</em></td>", fish->fish.error);
- fprintf (output_file, "</tr>");
+ fprintf (output_file, "<tr>");
+ fprintf (output_file, "<td><em>total</em></td>");
+ fprintf (output_file, "<td class='r'><em>%3.0f</em></td>", fish->fish_path.cost);
+ fprintf (output_file, "<td class='r'><em>%e</em></td>", fish->fish.error);
+ fprintf (output_file, "</tr>");
fprintf (output_file, "</table>");
fprintf (output_file, "</div>");
}
fprintf (output_file, "</a></td>\n");
break;
+
case BABL_FISH_REFERENCE:
fprintf (output_file, "<td class='cell'%s><a href='javascript:o()'> ",
- fish->fish.processings > 0 ? " style='background-color: #69f'":"");
+ fish->fish.processings > 0 ? " style='background-color: #69f'" : "");
fprintf (output_file, "<div class='tooltip'>");
fprintf (output_file, "<h3><span class='g'>Reference</span> %s <span class='g'>to</span> %s</h3>", source->instance.name, destination->instance.name);
- if (fish->fish.processings > 0)
- {
- fprintf (output_file, "<span class='g'>usecs:</span>%li<br/>", fish->fish.usecs);
- fprintf (output_file, "<span class='g'>Processings:</span>%i<br/>", fish->fish.processings);
- fprintf (output_file, "<span class='g'>Pixels:</span>%li<br/>", fish->fish.pixels);
- }
+ if (fish->fish.processings > 0)
+ {
+ fprintf (output_file, "<span class='g'>usecs:</span>%li<br/>", fish->fish.usecs);
+ fprintf (output_file, "<span class='g'>Processings:</span>%i<br/>", fish->fish.processings);
+ fprintf (output_file, "<span class='g'>Pixels:</span>%li<br/>", fish->fish.pixels);
+ }
fprintf (output_file, "</div>");
fprintf (output_file, "</a></td>\n");
break;
- default:
+
+ default:
babl_assert (0);
break;
}
return 0;
}
-static int source_no=0;
+static int source_no = 0;
static int
table_source_each (Babl *babl,
void *userdata)
{
- char expanded_name[512];
+ char expanded_name[512];
const char *s;
- char *d;
+ char *d;
- s=babl->instance.name;
- d=&expanded_name[0];
+ s = babl->instance.name;
+ d = &expanded_name[0];
while (*s)
{
switch (*s)
{
case ' ':
- *(d++)='&';
- *(d++)='n';
- *(d++)='b';
- *(d++)='s';
- *(d++)='p';
- *(d++)=';';
- *(d) ='\0';
+ *(d++) = '&';
+ *(d++) = 'n';
+ *(d++) = 'b';
+ *(d++) = 's';
+ *(d++) = 'p';
+ *(d++) = ';';
+ *(d) = '\0';
s++;
break;
+
default:
- *(d++)=*(s++);
- *(d) ='\0';
+ *(d++) = *(s++);
+ *(d) = '\0';
break;
}
}
fprintf (output_file, "<dl>");
fprintf (output_file, "<dt>bytes/pixel</dt><dd>%i</dd>", babl->format.bytes_per_pixel);
- fprintf (output_file, "<dt>model</dt><dd>%s</dd>", BABL(babl->format.model)->instance.name );
+ fprintf (output_file, "<dt>model</dt><dd>%s</dd>", BABL (babl->format.model)->instance.name);
fprintf (output_file, "<dt>loss</dt><dd>%f</dd>", babl_format_loss (babl));
fprintf (output_file, "<dt>components</dt><dd><table class='nopad'>");
- for (i=0; i< babl->format.components; i++)
+ for (i = 0; i < babl->format.components; i++)
{
fprintf (output_file, "<tr><td class='type'>%s</td><td class='component'>%s</td></tr>",
- BABL(babl->format.type[i])->instance.name,
- BABL(babl->format.component[i])->instance.name );
+ BABL (babl->format.type[i])->instance.name,
+ BABL (babl->format.component[i])->instance.name);
}
fprintf (output_file, "</table></dd></dl>");
{
double error, cost;
- if (BABL(babl->conversion.source)->class_type != BABL_FORMAT)
+ if (BABL (babl->conversion.source)->class_type != BABL_FORMAT)
return 0;
error = babl_conversion_error (&babl->conversion);
- cost = babl_conversion_cost (&babl->conversion);
+ cost = babl_conversion_cost (&babl->conversion);
- if (error>0.01)
+ if (error > 0.01)
{
fprintf (output_file, "<dt style='background-color: #fcc;'>%s</dt>", babl->instance.name);
fprintf (output_file, "<dd style='background-color: #fcc;'>");
fprintf (output_file, "<dt>%s</dt><dd>", babl->instance.name);
}
fprintf (output_file, "<em>error:</em> %f <em>cost:</em> %4.0f <em>processings:</em> %i <em>pixels:</em> %li", error, cost,
- babl->conversion.processings, babl->conversion.pixels);
+ babl->conversion.processings, babl->conversion.pixels);
fprintf (output_file, "</dd>");
return 0;
output_file = file;
fprintf (output_file,
-"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
-"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n"
-"<html>\n"
-"<head>\n"
-"<title>BablFishPath introspection</title>\n"
-
- "<style type='text/css'>"
- " body {"
- " font-family: sans;"
- " margin-left: 1em;"
- " }"
- " .cell {"
- " overflow : none;"
- " height: 1em;"
- " font-family: monospace;"
- " border: 1px solid #eee;"
- " padding: 0;"
- " margin : 0;"
- "}"
- ".cell>a {"
- " text-decoration: none;"
- " color: black;"
- " cursor: help;"
- "}"
- "div.tooltip {"
- " border: 0.2em solid black;"
- " padding-top: 1em;"
- " padding-right: 2em;"
- " display: none;"
- " padding-left: 2em;"
- " padding-bottom: 3em;"
- " background-color: white;"
- " background-repeat: no-repeat;"
- " background-image: url(graphics/babl-48x48.png);"
- " background-position: bottom right;"
- " color: black;"
- "}"
- " .cell>a:hover {"
- " background-color: black;"
- " color: white;"
- "}"
- " .format_name {"
- " height: 1em;"
- " background-color: #eee;"
- " padding-right: 0.5em;"
- " padding-left: 0.5em;"
- " border-bottom: 1px solid #fff;"
- "}"
- " .format_name>a {"
- " text-decoration: none;"
- " color: blue;"
- " cursor: help;"
- " }"
- " .format_name>a:hover {"
- " background-color: blue;"
- " color: white;"
- " }"
-
- "a:hover>div.tooltip {"
- " display: block;"
- " position: fixed;"
- " bottom: 0;"
- " right: 0;"
- "}"
-
- "td.component {"
- " background-color: #060;"
- " padding-left: 0.5em;"
- " padding-top: 0.1em;"
- " padding-bottom: 0.1em;"
- " overflow: hidden;"
- " width: 4em;"
- " color: white;"
- " border: 1px solid white;"
- "}"
- "td.type {"
- " background-color: #006;"
- " padding-left: 0.5em;"
- " padding-top: 0.1em;"
- " padding-bottom: 0.1em;"
- " overflow: hidden;"
- " width: 4em;"
- " color: white;"
- " border: 1px solid white;"
- "}"
- ".g {"
- " color: gray;"
- "}"
- ".r {"
- " text-align: right;"
- "}"
-
- "</style>"
-
-"<script type='text/javascript'>"
-"var tick_count=0;"
-"function o ()"
-"{"
-" tick_count++;"
-" if (tick_count == 11)"
-" alert(\"«The mind is it's own place,\\nand in itself can make a heaven of hell;\\na hell of heaven.»\\n--Milton\");"
-" else if (tick_count == 42)"
-" alert(\"«So long and thanks for all the fish.»\\n--Adams\");"
-"}"
-"</script>"
-
-
-"</head>\n");
-
- fprintf (output_file, "<body>\n");
+ "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
+ "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n"
+ "<html>\n"
+ "<head>\n"
+ "<title>BablFishPath introspection</title>\n"
+
+ "<style type='text/css'>"
+ " body {"
+ " font-family: sans;"
+ " margin-left: 1em;"
+ " }"
+ " .cell {"
+ " overflow : none;"
+ " height: 1em;"
+ " font-family: monospace;"
+ " border: 1px solid #eee;"
+ " padding: 0;"
+ " margin : 0;"
+ "}"
+ ".cell>a {"
+ " text-decoration: none;"
+ " color: black;"
+ " cursor: help;"
+ "}"
+ "div.tooltip {"
+ " border: 0.2em solid black;"
+ " padding-top: 1em;"
+ " padding-right: 2em;"
+ " display: none;"
+ " padding-left: 2em;"
+ " padding-bottom: 3em;"
+ " background-color: white;"
+ " background-repeat: no-repeat;"
+ " background-image: url(graphics/babl-48x48.png);"
+ " background-position: bottom right;"
+ " color: black;"
+ "}"
+ " .cell>a:hover {"
+ " background-color: black;"
+ " color: white;"
+ "}"
+ " .format_name {"
+ " height: 1em;"
+ " background-color: #eee;"
+ " padding-right: 0.5em;"
+ " padding-left: 0.5em;"
+ " border-bottom: 1px solid #fff;"
+ "}"
+ " .format_name>a {"
+ " text-decoration: none;"
+ " color: blue;"
+ " cursor: help;"
+ " }"
+ " .format_name>a:hover {"
+ " background-color: blue;"
+ " color: white;"
+ " }"
+
+ "a:hover>div.tooltip {"
+ " display: block;"
+ " position: fixed;"
+ " bottom: 0;"
+ " right: 0;"
+ "}"
+
+ "td.component {"
+ " background-color: #060;"
+ " padding-left: 0.5em;"
+ " padding-top: 0.1em;"
+ " padding-bottom: 0.1em;"
+ " overflow: hidden;"
+ " width: 4em;"
+ " color: white;"
+ " border: 1px solid white;"
+ "}"
+ "td.type {"
+ " background-color: #006;"
+ " padding-left: 0.5em;"
+ " padding-top: 0.1em;"
+ " padding-bottom: 0.1em;"
+ " overflow: hidden;"
+ " width: 4em;"
+ " color: white;"
+ " border: 1px solid white;"
+ "}"
+ ".g {"
+ " color: gray;"
+ "}"
+ ".r {"
+ " text-align: right;"
+ "}"
+
+ "</style>"
+
+ "<script type='text/javascript'>"
+ "var tick_count=0;"
+ "function o ()"
+ "{"
+ " tick_count++;"
+ " if (tick_count == 11)"
+ " alert(\"«The mind is it's own place,\\nand in itself can make a heaven of hell;\\na hell of heaven.»\\n--Milton\");"
+ " else if (tick_count == 42)"
+ " alert(\"«So long and thanks for all the fish.»\\n--Adams\");"
+ "}"
+ "</script>"
+
+
+ "</head>\n");
+
+ fprintf (output_file, "<body>\n");
fprintf (output_file, "<h1>BablFishPath introspection</h1>");
fprintf (output_file, "<p>Instrumentation and pathlengths.</p>");
- fprintf (output_file, "<table cellspacing='0'><tr><td>Source format</td><td colspan='32'>Destination formats</td></tr>\n");
+ fprintf (output_file, "<table cellspacing='0'><tr><td>Source format</td><td colspan='32'>Destination formats</td></tr>\n");
babl_format_each (table_source_each, NULL);
static int
-match_conversion (Babl *conversion,
- void *inout)
+match_conversion (Babl *conversion,
+ void *inout)
{
void **data = inout;
- if ((Babl *) conversion->conversion.destination == (Babl*) *data)
+ if ((Babl *) conversion->conversion.destination == (Babl *) *data)
{
- *data = (void *)conversion;
+ *data = (void *) conversion;
return 1;
}
return 0;
babl_conversion_find (void *source,
void *destination)
{
- void *data=destination;
+ void *data = destination;
- babl_list_each ((void*)BABL(source)->type.from, match_conversion, &data);
+ babl_list_each ((void *) BABL (source)->type.from, match_conversion, &data);
if (data == destination)
return NULL;
return data;
Babl *ret;
} BablFishingData;
-static int
+static int
fishing_result_examine (Babl *babl,
void *void_data)
{
BablFishingData *data = void_data;
- if ((void*)data->source == (void*)babl->fish.source &&
- (void*)data->destination == (void*)babl->fish.destination)
+ if ((void *) data->source == (void *) babl->fish.source &&
+ (void *) data->destination == (void *) babl->fish.destination)
{
- data->ret = babl;
- return 1; /* stop iterating */
+ data->ret = babl;
+ return 1; /* stop iterating */
}
return 0; /* continue iterating */
}
-static Babl *
-go_fishing (Babl *source,
- Babl *destination)
+static Babl *
+go_fishing (Babl *source,
+ Babl *destination)
{
{
BablFishingData data;
- data.source = source;
+ data.source = source;
data.destination = destination;
- data.ret = NULL;
+ data.ret = NULL;
babl_db_each (db, fishing_result_examine, &data);
return data.ret;
if (!source_format)
{
- source_format = babl_format ((char*)source);
+ source_format = babl_format ((char *) source);
}
if (!source_format)
if (!destination_format)
{
- destination_format = babl_format ((char*)destination);
+ destination_format = babl_format ((char *) destination);
}
if (!destination_format)
return NULL;
}
- {
- Babl *lucky;
- lucky = go_fishing (source_format, destination_format);
- if (lucky)
- return lucky;
- }
-
+ {
+ Babl *lucky;
+ lucky = go_fishing (source_format, destination_format);
+ if (lucky)
+ return lucky;
+ }
+
if (0)
{
- Babl *shortcut_conversion;
-
- shortcut_conversion = babl_conversion_find (
- source_format, destination_format);
+ Babl *shortcut_conversion;
- if (shortcut_conversion)
- {
- return babl_fish_simple (&(shortcut_conversion->conversion));
- }
- }
+ shortcut_conversion = babl_conversion_find (
+ source_format, destination_format);
+
+ if (shortcut_conversion)
+ {
+ return babl_fish_simple (&(shortcut_conversion->conversion));
+ }
+ }
{
Babl *fish_path;
-
+
fish_path = babl_fish_path (source_format, destination_format);
if (fish_path)
{
- return fish_path;
+ return fish_path;
}
}
{
BablImage *source_image = NULL;
BablImage *destination_image = NULL;
- long ret=0;
+ long ret = 0;
switch (babl->class_type)
{
case BABL_FISH_PATH:
#if 0
- if (BABL_IS_BABL (source))
- source_image = source;
+ if (BABL_IS_BABL (source))
+ source_image = source;
#endif
- if (!source_image)
- source_image = (BablImage*) babl_image_from_linear (
- source, (Babl*)babl->fish.source);
+ if (!source_image)
+ source_image = (BablImage *) babl_image_from_linear (
+ source, (Babl *) babl->fish.source);
#if 0
- if (BABL_IS_BABL (destination))
- destination_image = destination;
+ if (BABL_IS_BABL (destination))
+ destination_image = destination;
#endif
- if (!destination_image)
- destination_image = (BablImage*) babl_image_from_linear (
- destination, (Babl*)babl->fish.destination);
-
- if (babl->class_type == BABL_FISH_REFERENCE)
- {
- ret = babl_fish_reference_process (babl, source, destination, n);
- }
- else if (babl->class_type == BABL_FISH_PATH)
- {
- ret = babl_fish_path_process (babl, source, destination, n);
- }
- else if (babl->class_type == BABL_FISH_SIMPLE)
- {
- if (BABL(babl->fish_simple.conversion)->class_type==BABL_CONVERSION_LINEAR)
- {
- ret = babl_conversion_process (BABL(babl->fish_simple.conversion),
- source, destination, n);
- }
- else
- {
- ret = babl_conversion_process (BABL(babl->fish_simple.conversion),
- (char*)source_image, (char*)destination_image, n);
- }
- }
+ if (!destination_image)
+ destination_image = (BablImage *) babl_image_from_linear (
+ destination, (Babl *) babl->fish.destination);
+
+ if (babl->class_type == BABL_FISH_REFERENCE)
+ {
+ ret = babl_fish_reference_process (babl, source, destination, n);
+ }
+ else if (babl->class_type == BABL_FISH_PATH)
+ {
+ ret = babl_fish_path_process (babl, source, destination, n);
+ }
+ else if (babl->class_type == BABL_FISH_SIMPLE)
+ {
+ if (BABL (babl->fish_simple.conversion)->class_type == BABL_CONVERSION_LINEAR)
+ {
+ ret = babl_conversion_process (BABL (babl->fish_simple.conversion),
+ source, destination, n);
+ }
+ else
+ {
+ ret = babl_conversion_process (BABL (babl->fish_simple.conversion),
+ (char *) source_image, (char *) destination_image, n);
+ }
+ }
babl_free (source_image);
babl_free (destination_image);
break;
+
default:
babl_log ("NYI");
ret = -1;
return ret;
}
-static int
+static int
each_babl_fish_destroy (Babl *babl,
void *data)
{
return 0; /* continue iterating */
}
-BABL_DEFINE_INIT (fish)
+BABL_DEFINE_INIT (fish)
BABL_DEFINE_DESTROY (fish)
-BABL_DEFINE_EACH (fish)
+BABL_DEFINE_EACH (fish)
#include "babl-internal.h"
#include "babl-db.h"
-static int
+static int
each_babl_format_destroy (Babl *babl,
void *data)
{
{
int i;
/* i is desintation position */
- for (i=0 ; i<model->components; i++)
+ for (i = 0; i < model->components; i++)
{
int j;
- for (j=0;j<components;j++)
+ for (j = 0; j < components; j++)
{
if (component[j] == model->component[i])
goto component_found;
}
babl_fatal ("matching source component for %s in model %s not found",
model->component[i]->instance.name, model->instance.name);
- component_found:
+component_found:
;
}
}
/* allocate all memory in one chunk */
- babl = babl_malloc (sizeof (BablFormat) +
- strlen (name) + 1 +
- sizeof (BablComponent*) * (components) +
- sizeof (BablSampling*) * (components) +
- sizeof (BablType*) * (components) +
- sizeof (int) * (components) +
- sizeof (int) * (components));
+ babl = babl_malloc (sizeof (BablFormat) +
+ strlen (name) + 1 +
+ sizeof (BablComponent *) * (components) +
+ sizeof (BablSampling *) * (components) +
+ sizeof (BablType *) * (components) +
+ sizeof (int) * (components) +
+ sizeof (int) * (components));
babl->format.from = NULL;
- babl->format.component = (void*)(((char *)babl) + sizeof (BablFormat));
- babl->format.type = (void*)(((char *)babl->format.component) + sizeof (BablComponent*) * (components));
- babl->format.sampling = (void*)(((char *)babl->format.type) + sizeof (BablType*) * (components));
- babl->instance.name = ((char *)babl->format.sampling) + sizeof (BablSampling*) * (components);
-
- babl->class_type = BABL_FORMAT;
- babl->instance.id = id;
+ babl->format.component = (void *) (((char *) babl) + sizeof (BablFormat));
+ babl->format.type = (void *) (((char *) babl->format.component) + sizeof (BablComponent *) * (components));
+ babl->format.sampling = (void *) (((char *) babl->format.type) + sizeof (BablType *) * (components));
+ babl->instance.name = ((char *) babl->format.sampling) + sizeof (BablSampling *) * (components);
+
+ babl->class_type = BABL_FORMAT;
+ babl->instance.id = id;
strcpy (babl->instance.name, name);
babl->format.model = model;
babl->format.components = components;
- memcpy (babl->format.component, component, sizeof (BablComponent*) * components);
- memcpy (babl->format.type , type , sizeof (BablType*) * components);
- memcpy (babl->format.sampling , sampling , sizeof (BablSampling*) * components);
+ memcpy (babl->format.component, component, sizeof (BablComponent *) * components);
+ memcpy (babl->format.type, type, sizeof (BablType *) * components);
+ memcpy (babl->format.sampling, sampling, sizeof (BablSampling *) * components);
- babl->format.planar = planar;
+ babl->format.planar = planar;
babl->format.bytes_per_pixel = 0;
{
int i;
- for (i=0;i<components;i++)
- babl->format.bytes_per_pixel += type[i]->bits/8;
+ for (i = 0; i < components; i++)
+ babl->format.bytes_per_pixel += type[i]->bits / 8;
}
babl->format.loss = -1.0;
}
-static char buf[512]="";
+static char buf[512] = "";
static const char *
create_name (BablModel *model,
BablComponent **component,
BablType **type)
{
- char *p = &buf[0];
- int i;
- int same_types=1;
- BablType **t=type;
- BablType *first_type = *type;
- BablComponent **c1=component;
- BablComponent **c2=model->component;
-
-
+ char *p = &buf[0];
+ int i;
+ int same_types = 1;
+ BablType **t = type;
+ BablType *first_type = *type;
+ BablComponent **c1 = component;
+ BablComponent **c2 = model->component;
+
+
sprintf (p, "%s ", model->instance.name);
- p+=strlen (model->instance.name) + 1;
+ p += strlen (model->instance.name) + 1;
- i=components;
+ i = components;
while (i--)
{
if (first_type != *t)
{
- same_types=0;
+ same_types = 0;
break;
}
t++;
}
- if (same_types &&
+ if (same_types &&
components != model->components)
same_types = 0;
-
- i=components;
+
+ i = components;
while (same_types && i--)
{
if (*c1 != *c2)
{
- same_types=0;
+ same_types = 0;
break;
}
c1++;
return buf;
}
- i=components;
+ i = components;
while (i--)
{
- sprintf (p, "(%s as %s) ",
- (*component)->instance.name,
- (*type)->instance.name);
- p+=strlen ((*component)->instance.name) +
- strlen ((*type)->instance.name ) + strlen("( as ) ");
+ sprintf (p, "(%s as %s) ",
+ (*component)->instance.name,
+ (*type)->instance.name);
+ p += strlen ((*component)->instance.name) +
+ strlen ((*type)->instance.name) + strlen ("( as ) ");
component++;
type++;
}
babl_format_new (void *first_arg,
...)
{
- va_list varg;
- Babl *babl;
- int id = 0;
- int planar = 0;
- int components = 0;
- BablModel *model = NULL;
- BablComponent *component [BABL_MAX_COMPONENTS];
- BablSampling *sampling [BABL_MAX_COMPONENTS];
- BablType *type [BABL_MAX_COMPONENTS];
-
- BablSampling *current_sampling = (BablSampling*) babl_sampling (1,1);
- BablType *current_type = (BablType*) babl_type_id (BABL_DOUBLE);
- char *name = NULL;
- void *arg = first_arg;
+ va_list varg;
+ Babl *babl;
+ int id = 0;
+ int planar = 0;
+ int components = 0;
+ BablModel *model = NULL;
+ BablComponent *component [BABL_MAX_COMPONENTS];
+ BablSampling *sampling [BABL_MAX_COMPONENTS];
+ BablType *type [BABL_MAX_COMPONENTS];
+
+ BablSampling *current_sampling = (BablSampling *) babl_sampling (1, 1);
+ BablType *current_type = (BablType *) babl_type_id (BABL_DOUBLE);
+ char *name = NULL;
+ void *arg = first_arg;
va_start (varg, first_arg);
-
+
while (1)
{
if (BABL_IS_BABL (arg))
{
- Babl *babl = (Babl*)arg;
+ Babl *babl = (Babl *) arg;
switch (babl->class_type)
{
case BABL_TYPE:
case BABL_TYPE_FLOAT:
case BABL_TYPE_INTEGER:
- current_type = (BablType*) babl;
+ current_type = (BablType *) babl;
break;
+
case BABL_COMPONENT:
if (!model)
{
babl_fatal ("no model specified before component %s",
babl->instance.name);
}
- component [components] = (BablComponent*) babl;
+ component [components] = (BablComponent *) babl;
type [components] = current_type;
sampling [components] = current_sampling;
components++;
- if (components>=BABL_MAX_COMPONENTS)
+ if (components >= BABL_MAX_COMPONENTS)
{
babl_fatal ("maximum number of components (%i) exceeded for %s",
BABL_MAX_COMPONENTS, name);
}
break;
+
case BABL_SAMPLING:
- current_sampling = (BablSampling*)arg;
- break;
+ current_sampling = (BablSampling *) arg;
+ break;
+
case BABL_MODEL:
- if (model)
- {
+ if (model)
+ {
babl_log ("args=(%s): model %s already requested",
- babl->instance.name, model->instance.name);
- }
- model = (BablModel*)arg;
- break;
+ babl->instance.name, model->instance.name);
+ }
+ model = (BablModel *) arg;
+ break;
+
case BABL_INSTANCE:
case BABL_FORMAT:
case BABL_CONVERSION:
case BABL_IMAGE:
case BABL_EXTENSION:
babl_log ("%s unexpected",
- babl_class_name (babl->class_type));
+ babl_class_name (babl->class_type));
break;
+
case BABL_SKY: /* shut up compiler */
break;
}
{
name = va_arg (varg, char *);
}
-
+
else if (!strcmp (arg, "packed"))
{
planar = 0;
}
-
+
else if (!strcmp (arg, "planar"))
{
planar = 1;
}
-
+
else
{
babl_fatal ("unhandled argument '%s' for format '%s'", arg, name);
if (!arg)
break;
}
-
- va_end (varg);
- babl = format_new (name?name:create_name (model, components, component, type),
+ va_end (varg);
+
+ babl = format_new (name ? name : create_name (model, components, component, type),
id,
planar, components, model,
component, sampling, type);
-
- {
+
+ {
Babl *ret = babl_db_insert (db, babl);
- if (ret!=babl)
- babl_free (babl);
+ if (ret != babl)
+ babl_free (babl);
return ret;
}
}
Babl *type)
{
BablComponent *component[10];
- int i;
+ int i;
- for (i=0;i<model->model.components;i++)
+ for (i = 0; i < model->model.components; i++)
{
- component[i]= model->model.component[i];
+ component[i] = model->model.component[i];
}
- component[i]=NULL;
+ component[i] = NULL;
return babl_format_new (
- model,
- type,
- component[0],
- component[1],
- component[2],
- component[3],
- component[4],
- component[5],
- component[6],
- component[7],
- component[8],
- component[9],
- NULL
- );
+ model,
+ type,
+ component[0],
+ component[1],
+ component[2],
+ component[3],
+ component[4],
+ component[5],
+ component[6],
+ component[7],
+ component[8],
+ component[9],
+ NULL
+ );
}
-#define test_pixels 256
+#define test_pixels 256
static double *
test_create (void)
int i;
srandom (20050728);
-
+
test = babl_malloc (sizeof (double) * test_pixels * 4);
for (i = 0; i < test_pixels * 4; i++)
- test [i] = (double) random () / RAND_MAX;
+ test [i] = (double) random () / RAND_MAX;
return test;
}
void *destination;
double *transformed;
- Babl *ref_fmt;
- Babl *fmt;
- Babl *fish_to;
- Babl *fish_from;
+ Babl *ref_fmt;
+ Babl *fmt;
+ Babl *fish_to;
+ Babl *fish_from;
- ref_fmt = babl_format_new (
- babl_model ("RGBA"),
- babl_type ("double"),
- babl_component ("R"),
- babl_component ("G"),
- babl_component ("B"),
- babl_component ("A"),
- NULL);
+ ref_fmt = babl_format_new (
+ babl_model ("RGBA"),
+ babl_type ("double"),
+ babl_component ("R"),
+ babl_component ("G"),
+ babl_component ("B"),
+ babl_component ("A"),
+ NULL);
if (babl->format.loss != -1.0)
return babl->format.loss;
-
- fmt = babl;
+
+ fmt = babl;
fish_to = babl_fish_reference (ref_fmt, fmt);
fish_from = babl_fish_reference (fmt, ref_fmt);
-
- test = test_create ();
+
+ test = test_create ();
original = babl_calloc (test_pixels, fmt->format.bytes_per_pixel);
clipped = babl_calloc (test_pixels, ref_fmt->format.bytes_per_pixel);
destination = babl_calloc (test_pixels, fmt->format.bytes_per_pixel);
- transformed = babl_calloc (test_pixels, ref_fmt->format.bytes_per_pixel);
+ transformed = babl_calloc (test_pixels, ref_fmt->format.bytes_per_pixel);
- babl_process (fish_to, test, original, test_pixels);
- babl_process (fish_from, original, clipped, test_pixels);
- babl_process (fish_to, clipped, destination, test_pixels);
+ babl_process (fish_to, test, original, test_pixels);
+ babl_process (fish_from, original, clipped, test_pixels);
+ babl_process (fish_to, clipped, destination, test_pixels);
babl_process (fish_from, destination, transformed, test_pixels);
- loss = babl_rel_avg_error (clipped, test, test_pixels*4);
-
- fish_to->fish.processings-=2;
- fish_from->fish.processings-=2;
- fish_to->fish.pixels-=test_pixels*2;
- fish_from->fish.pixels -= test_pixels*2;
+ loss = babl_rel_avg_error (clipped, test, test_pixels * 4);
+
+ fish_to->fish.processings -= 2;
+ fish_from->fish.processings -= 2;
+ fish_to->fish.pixels -= test_pixels * 2;
+ fish_from->fish.pixels -= test_pixels * 2;
babl_free (original);
babl_free (clipped);
babl->image.model = model;
babl->image.components = components;
- memcpy (babl->image.component, component, components * sizeof(void*));
- memcpy (babl->image.type, type, components * sizeof(void*));
- memcpy (babl->image.data, data, components * sizeof(void*));
- memcpy (babl->image.pitch, pitch, components * sizeof(int));
- memcpy (babl->image.stride, stride, components * sizeof(int));
+ memcpy (babl->image.component, component, components * sizeof (void *));
+ memcpy (babl->image.type, type, components * sizeof (void *));
+ memcpy (babl->image.data, data, components * sizeof (void *));
+ memcpy (babl->image.pitch, pitch, components * sizeof (int));
+ memcpy (babl->image.stride, stride, components * sizeof (int));
return babl;
}
Babl *
-babl_image_from_linear (char *buffer,
- Babl *format)
+babl_image_from_linear (char *buffer,
+ Babl *format)
{
Babl *babl;
- BablModel *model = NULL;
+ BablModel *model = NULL;
int components = 0;
int i;
BablComponent *component [BABL_MAX_COMPONENTS];
int pitch [BABL_MAX_COMPONENTS];
int stride [BABL_MAX_COMPONENTS];
- int offset=0;
- int calc_pitch=0;
+ int offset = 0;
+ int calc_pitch = 0;
babl_assert (format);
babl_assert (format->class_type == BABL_FORMAT ||
format->class_type == BABL_MODEL);
-
+
switch (format->class_type)
{
case BABL_FORMAT:
- model = (BablModel*) format->format.model;
+ model = (BablModel *) format->format.model;
components = format->format.components;
- memcpy(component, format->format.component, sizeof (Babl*) * components);
- memcpy(sampling, format->format.sampling, sizeof (Babl*) * components);
- memcpy(type , format->format.type, sizeof (Babl*) * components);
+ memcpy (component, format->format.component, sizeof (Babl *) * components);
+ memcpy (sampling, format->format.sampling, sizeof (Babl *) * components);
+ memcpy (type, format->format.type, sizeof (Babl *) * components);
- for (i=0; i < components; i++)
+ for (i = 0; i < components; i++)
{
calc_pitch += (type[i]->bits / 8);
}
- for (i=0; i < components; i++)
+ for (i = 0; i < components; i++)
{
- pitch[i] = calc_pitch;
- stride[i] = 0;
- data[i] = buffer + offset;
- offset += (type[i]->bits / 8);
+ pitch[i] = calc_pitch;
+ stride[i] = 0;
+ data[i] = buffer + offset;
+ offset += (type[i]->bits / 8);
}
break;
+
case BABL_MODEL:
- model = (BablModel*) format;
+ model = (BablModel *) format;
components = format->format.components;
- for (i=0; i < components; i++)
+ for (i = 0; i < components; i++)
{
calc_pitch += (64 / 8); /*< known to be double when we create from model */
}
- memcpy(component, model->component, sizeof (Babl*) * components);
- for (i=0; i < components; i++)
+ memcpy (component, model->component, sizeof (Babl *) * components);
+ for (i = 0; i < components; i++)
{
- sampling[i] = (BablSampling*)babl_sampling (1,1);
- type[i] = (BablType*)babl_type_id (BABL_DOUBLE);
- pitch[i] = calc_pitch;
- stride[i] = 0;
- data[i] = buffer + offset;
- offset += (type[i]->bits / 8);
+ sampling[i] = (BablSampling *) babl_sampling (1, 1);
+ type[i] = (BablType *) babl_type_id (BABL_DOUBLE);
+ pitch[i] = calc_pitch;
+ stride[i] = 0;
+ data[i] = buffer + offset;
+ offset += (type[i]->bits / 8);
}
break;
+
default:
babl_log ("Eeeek!");
break;
}
babl = image_new (
- (BablFormat*)format,
- model, components,
- component, sampling, type, data, pitch, stride);
+ (BablFormat *) format,
+ model, components,
+ component, sampling, type, data, pitch, stride);
return babl;
}
{
va_list varg;
Babl *babl;
- int components= 0;
- BablFormat *format = NULL;
- BablModel *model = NULL;
+ int components = 0;
+ BablFormat *format = NULL;
+ BablModel *model = NULL;
BablComponent *component [BABL_MAX_COMPONENTS];
BablSampling *sampling [BABL_MAX_COMPONENTS];
BablType *type [BABL_MAX_COMPONENTS];
int pitch [BABL_MAX_COMPONENTS];
int stride [BABL_MAX_COMPONENTS];
- const char *arg = first;
+ const char *arg = first;
va_start (varg, first);
if (BABL_IS_BABL (arg))
{
- Babl *babl = (Babl*)arg;
+ Babl *babl = (Babl *) arg;
if (babl->class_type == BABL_COMPONENT)
{
- new_component = (BablComponent *)babl;
+ new_component = (BablComponent *) babl;
}
else
{
- babl_log ("%s unexpected", babl_class_name (babl->class_type));
- return NULL;
+ babl_log ("%s unexpected", babl_class_name (babl->class_type));
+ return NULL;
}
}
else
{
- new_component = (BablComponent*) babl_component (arg);
+ new_component = (BablComponent *) babl_component (arg);
}
/* FIXME: add error checking */
component [components] = new_component;
sampling [components] = NULL;
type [components] = NULL;
- data [components] = va_arg (varg, void*);
+ data [components] = va_arg (varg, void *);
pitch [components] = va_arg (varg, int);
stride [components] = va_arg (varg, int);
components++;
-
- if (components>=BABL_MAX_COMPONENTS)
+
+ if (components >= BABL_MAX_COMPONENTS)
{
babl_log ("maximum number of components (%i) exceeded", BABL_MAX_COMPONENTS);
}
arg = va_arg (varg, char *);
}
-
- va_end (varg);
+
+ va_end (varg);
babl = image_new (format, model, components, component, sampling, type, data, pitch, stride);
#include "babl-internal.h"
static const char *class_names[] =
- {
- "BablInstance",
- "BablType",
- "BablTypeInteger",
- "BablTypeFloat",
- "BablSampling",
- "BablComponent",
- "BablModel",
- "BablFormat",
- "BablConversion",
- "BablConversionLinear",
- "BablConversionPlane",
- "BablConversionPlanar",
- "BablFish",
- "BablFishReference",
- "BablFishSimple",
- "BablFishPath",
- "BablImage",
- "BablExtenstion",
- "BablSky"
- };
+{
+ "BablInstance",
+ "BablType",
+ "BablTypeInteger",
+ "BablTypeFloat",
+ "BablSampling",
+ "BablComponent",
+ "BablModel",
+ "BablFormat",
+ "BablConversion",
+ "BablConversionLinear",
+ "BablConversionPlane",
+ "BablConversionPlanar",
+ "BablFish",
+ "BablFishReference",
+ "BablFishSimple",
+ "BablFishPath",
+ "BablImage",
+ "BablExtenstion",
+ "BablSky"
+};
const char *
babl_class_name (BablClassType klass)
{
- return class_names[klass-BABL_INSTANCE];
+ return class_names[klass - BABL_INSTANCE];
}
/* global variable, indicating whether name lookups
{
char buf[512];
- sprintf (buf,"echo bt>/tmp/babl.gdb;"
- "gdb -q --batch -x /tmp/babl.gdb --pid=%i 2>/dev/null", getpid());
+ sprintf (buf, "echo bt>/tmp/babl.gdb;"
+ "gdb -q --batch -x /tmp/babl.gdb --pid=%i 2>/dev/null", getpid ());
system (buf);
}
babl_assert (source);
babl_assert (destination);
babl_assert (BABL_IS_BABL (babl));
- babl_assert (n>0);
+ babl_assert (n > 0);
/* matches all conversion classes */
if (babl->class_type >= BABL_CONVERSION &&
babl->class_type == BABL_FISH_PATH ||
babl->class_type == BABL_FISH_SIMPLE)
{
- long ret;
- long ticks = babl_ticks ();
- ret = babl_fish_process (babl, source, destination, n);
-
- ticks -= babl_ticks();
- ticks *= -1L;
-
- babl_total_usecs += ticks;
- babl->fish.usecs += ticks;
- babl->fish.processings++;
- babl->fish.pixels += ret;
- return ret;
+ long ret;
+ long ticks = babl_ticks ();
+ ret = babl_fish_process (babl, source, destination, n);
+
+ ticks -= babl_ticks ();
+ ticks *= -1L;
+
+ babl_total_usecs += ticks;
+ babl->fish.usecs += ticks;
+ babl->fish.processings++;
+ babl->fish.pixels += ret;
+ return ret;
}
babl_fatal ("eek");
#ifdef BABL_LOG
-static void sampling_introspect (Babl *babl);
-static void model_introspect (Babl *babl);
-static void type_introspect (Babl *babl);
-static void format_introspect (Babl *babl);
+static void sampling_introspect (Babl *babl);
+static void model_introspect (Babl *babl);
+static void type_introspect (Babl *babl);
+static void format_introspect (Babl *babl);
-static int each_introspect (Babl *babl,
- void *user_data);
+static int each_introspect (Babl *babl,
+ void *user_data);
#endif
void
{
#ifdef BABL_LOG
Babl *extender_backup = babl_extender ();
-
- babl_set_extender (babl_extension_quiet_log());
+
+ babl_set_extender (babl_extension_quiet_log ());
if (babl)
{
each_introspect (babl, NULL);
return;
}
- babl_log ("Introspection report");
- babl_log ("====================================================");
+ babl_log ("Introspection report");
+ babl_log ("====================================================");
babl_log ("");
babl_log ("Data Types:");
- babl_type_each (each_introspect, NULL);
+ babl_type_each (each_introspect, NULL);
babl_log ("");
babl_log ("Sampling (chroma subsampling) factors:");
- babl_sampling_each (each_introspect, NULL);
+ babl_sampling_each (each_introspect, NULL);
babl_log ("");
babl_log ("Components:");
- babl_component_each (each_introspect, NULL);
+ babl_component_each (each_introspect, NULL);
babl_log ("");
babl_log ("Models (of components):");
- babl_model_each (each_introspect, NULL);
+ babl_model_each (each_introspect, NULL);
babl_log ("");
babl_log ("Pixel formats:");
babl_format_each (each_introspect, NULL);
babl_log ("");
babl_log ("conversions:");
- babl_conversion_each (each_introspect, NULL);
+ babl_conversion_each (each_introspect, NULL);
babl_log ("");
babl_log ("extensions:");
- babl_extension_each (each_introspect, NULL);
+ babl_extension_each (each_introspect, NULL);
babl_log ("");
babl_log ("fishes");
- babl_fish_each (each_introspect, NULL);
+ babl_fish_each (each_introspect, NULL);
babl_log ("");
babl_set_extender (extender_backup);
static int list_length (void **list)
{
void **ptr;
- int len=0;
-
+ int len = 0;
+
ptr = list;
- while (NULL!=*ptr)
+ while (NULL != *ptr)
{
ptr++;
len++;
if (babl->type.from)
babl_log ("\t\tconversions from %s: %i",
- babl->instance.name, list_length ((void **)(babl->type.from)));
+ babl->instance.name, list_length ((void **) (babl->type.from)));
- ptr = (void **)babl->type.from;
+ ptr = (void **) babl->type.from;
- while (ptr && NULL!=*ptr)
+ while (ptr && NULL != *ptr)
{
- babl_log ("\t\t\t'%s'", ((Babl *)(*ptr))->instance.name);
+ babl_log ("\t\t\t'%s'", ((Babl *) (*ptr))->instance.name);
ptr++;
}
-
}
static void
model_introspect (Babl *babl)
{
int i;
+
babl_log ("\t\tcomponents=%i", babl->model.components);
- for (i=0; i< babl->model.components; i++)
+ for (i = 0; i < babl->model.components; i++)
{
babl_log ("\t\tindex[%i] = \"%s\"", i,
- BABL(babl->model.component[i])->instance.name );
+ BABL (babl->model.component[i])->instance.name);
}
}
format_introspect (Babl *babl)
{
int i;
+
babl_log ("\t\tmodel=\"%s\"", babl->format.model->instance.name);
babl_log ("\t\tplanar=%i", babl->format.planar);
- babl_log ("\t\tcomponents=%i", babl->format.components);
+ babl_log ("\t\tcomponents=%i", babl->format.components);
- for (i=0; i< babl->format.components; i++)
+ for (i = 0; i < babl->format.components; i++)
{
babl_log ("\t\tband[%i] type=\"%s\" sampling=\"%s\" component=\"%s\"",
- i, babl->format.type[i]->instance.name,
- babl->format.sampling[i]->instance.name,
- babl->format.component[i]->instance.name);
+ i, babl->format.type[i]->instance.name,
+ babl->format.sampling[i]->instance.name,
+ babl->format.component[i]->instance.name);
}
}
{
babl_log ("\t\tprocessings:%i pixels:%li",
babl->conversion.processings, babl->conversion.pixels);
- if (BABL(babl->conversion.source)->class_type == BABL_FORMAT)
+ if (BABL (babl->conversion.source)->class_type == BABL_FORMAT)
{
babl_log ("\t\terror: %f", babl_conversion_error (&babl->conversion));
}
void *user_data)
{
babl_log ("\t\"%s\"\t%i\t%s",
- babl->instance.name,
- babl->instance.id,
- babl_class_name (babl->class_type));
+ babl->instance.name,
+ babl->instance.id,
+ babl_class_name (babl->class_type));
switch (babl->class_type)
{
case BABL_TYPE:
type_introspect (babl);
item_conversions_introspect (babl);
break;
+
case BABL_COMPONENT:
break;
+
case BABL_MODEL:
model_introspect (babl);
item_conversions_introspect (babl);
break;
+
case BABL_FORMAT:
format_introspect (babl);
item_conversions_introspect (babl);
break;
+
case BABL_SAMPLING:
sampling_introspect (babl);
item_conversions_introspect (babl);
break;
+
case BABL_CONVERSION:
case BABL_CONVERSION_PLANE:
case BABL_CONVERSION_PLANAR:
case BABL_CONVERSION_LINEAR:
conversion_introspect (babl);
break;
+
case BABL_FISH:
case BABL_FISH_REFERENCE:
case BABL_FISH_SIMPLE:
fish_introspect (babl);
break;
+
default:
break;
}
#include <string.h>
#include "babl-internal.h"
-static void *(* malloc_f) (size_t size) = malloc;
-static void (* free_f) (void *ptr) = free;
+static void *(*malloc_f)(size_t size) = malloc;
+static void (*free_f)(void *ptr) = free;
static void *first_malloc_used = NULL;
static void *first_free_used = NULL;
void
-babl_set_malloc (void *(* malloc_function) (size_t size))
+babl_set_malloc (void *(*malloc_function)(size_t size))
{
malloc_f = malloc_function;
}
void
-babl_set_free (void (* free_function) (void *ptr))
+babl_set_free (void (*free_function)(void *ptr))
{
free_f = free_function;
}
typedef struct
{
- char *signature;
- size_t size;
+ char *signature;
+ size_t size;
} BablAllocInfo;
-#define OFFSET (sizeof(BablAllocInfo))
+#define OFFSET (sizeof (BablAllocInfo))
-#define BAI(ptr) ((BablAllocInfo*)(((char*)ptr)-OFFSET))
-#define IS_BAI(ptr) (BAI(ptr)->signature == signature)
+#define BAI(ptr) ((BablAllocInfo *) (((char *) ptr) - OFFSET))
+#define IS_BAI(ptr) (BAI (ptr)->signature == signature)
/* runtime statistics: */
static int mallocs = 0;
mem_stats (void)
{
static char buf[128];
+
sprintf (buf, "mallocs:%i callocs:%i strdups:%i dups:%i allocs:%i frees:%i reallocs:%i\t|",
- mallocs, callocs, strdups, dups, mallocs+callocs+strdups+dups, frees, reallocs);
+ mallocs, callocs, strdups, dups, mallocs + callocs + strdups + dups, frees, reallocs);
return buf;
}
functions_sanity (void)
{
if (first_malloc_used != malloc_f ||
- first_free_used != free_f)
+ first_free_used != free_f)
{
if (first_malloc_used == NULL)
{
}
}
}
-
-/* Allocate /size/ bytes of memory
+
+/* Allocate /size/ bytes of memory
*
* contents of memory undefined.
*/
functions_sanity ();
ret = malloc_f (size + OFFSET);
if (!ret)
- babl_fatal ("args=(%i): failed", size);
+ babl_fatal ("args=(%i): failed", size);
- BAI(ret + OFFSET)->signature = signature;
- BAI(ret + OFFSET)->size = size;
+ BAI (ret + OFFSET)->signature = signature;
+ BAI (ret + OFFSET)->size = size;
mallocs++;
- return (void*)(ret + OFFSET);
+ return (void *) (ret + OFFSET);
}
/* Create a duplicate allocation of the same size, note
babl_dup (void *ptr)
{
void *ret;
-
+
babl_assert (IS_BAI (ptr));
- ret = babl_malloc (BAI(ptr)->size);
- memcpy (ret, ptr, BAI(ptr)->size);
+ ret = babl_malloc (BAI (ptr)->size);
+ memcpy (ret, ptr, BAI (ptr)->size);
dups++;
mallocs--;
{
if (!ptr)
return;
- if(!IS_BAI(ptr))
+ if (!IS_BAI (ptr))
babl_fatal ("memory not allocated by babl allocator");
functions_sanity ();
- BAI(ptr)->signature=NULL;
- free_f (BAI(ptr));
+ BAI (ptr)->signature = NULL;
+ free_f (BAI (ptr));
frees++;
}
* common allocated memory between old and new size is preserved.
*/
void *
-babl_realloc (void *ptr,
- size_t size)
+babl_realloc (void *ptr,
+ size_t size)
{
void *ret = NULL;
babl_assert (IS_BAI (ptr));
- if (size==0)
+ if (size == 0)
{
babl_free (ptr);
return NULL;
}
if (!ret)
- babl_fatal ("args=(%p, %i): failed", ptr, size);
-
+ babl_fatal ("args=(%p, %i): failed", ptr, size);
+
return NULL;
}
babl_calloc (size_t nmemb,
size_t size)
{
- void *ret = babl_malloc (nmemb*size);
+ void *ret = babl_malloc (nmemb * size);
if (!ret)
- babl_fatal ("args=(%i, %i): failed", nmemb, size);
+ babl_fatal ("args=(%i, %i): failed", nmemb, size);
- memset (ret, 0, nmemb*size);
+ memset (ret, 0, nmemb * size);
callocs++;
mallocs--;
babl_sizeof (void *ptr)
{
babl_assert (IS_BAI (ptr));
- return BAI(ptr)->size;
+ return BAI (ptr)->size;
}
/* duplicate allocation needed for a string, and
{
char *ret;
- ret = babl_malloc (strlen (s)+1);
+ ret = babl_malloc (strlen (s) + 1);
if (!ret)
- babl_log ("args=(%s): failed", s);
- strcpy (ret, s);
+ babl_log ("args=(%s): failed", s);
+ strcpy (ret, s);
strdups++;
mallocs--;
const char *src)
{
char *ret;
- int src_len;
- int dst_len;
+ int src_len;
+ int dst_len;
src_len = strlen (src);
if (!dest)
{
- ret = babl_malloc (src_len+1);
+ ret = babl_malloc (src_len + 1);
strcpy (ret, src);
return ret;
}
babl_assert (IS_BAI (dest));
dst_len = strlen (dest);
-
+
ret = dest;
if (babl_sizeof (dest) < src_len + dst_len + 1)
{
size_t new_size = babl_sizeof (dest);
while (new_size < src_len + dst_len + 1)
- new_size*=2;
+ new_size *= 2;
ret = babl_realloc (dest, new_size);
}
if (frees != mallocs + strdups + callocs)
{
babl_log ("memory usage does not add up!\n"
-"%s\n"
-"\tbalance: %i-%i=%i\n",
- mem_stats(), (strdups+mallocs+callocs),frees, (strdups+mallocs+callocs)-frees);
+ "%s\n"
+ "\tbalance: %i-%i=%i\n",
+ mem_stats (), (strdups + mallocs + callocs), frees, (strdups + mallocs + callocs) - frees);
return -1;
}
return 0;
#include "babl-db.h"
-static int
+static int
each_babl_model_destroy (Babl *babl,
- void *data)
+ void *data)
{
babl_free (babl->model.from);
babl_free (babl);
return 0; /* continue iterating */
}
-static char buf[512]="";
+static char buf[512] = "";
static const char *
create_name (const char *name,
BablComponent **component)
{
char *p = buf;
+
if (name)
return name;
while (components--)
{
sprintf (p, (*component)->instance.name);
- p+=strlen ((*component)->instance.name);
+ p += strlen ((*component)->instance.name);
component++;
}
return buf;
{
Babl *babl;
- babl = babl_malloc (sizeof (BablModel) +
- sizeof (BablComponent*) * (components) +
- strlen (name) + 1);
- babl->model.component = (void*)(((char*)babl) + sizeof (BablModel));
- babl->instance.name = (void*)(((char*)babl->model.component) + sizeof (BablComponent*) * (components));
-
+ babl = babl_malloc (sizeof (BablModel) +
+ sizeof (BablComponent *) * (components) +
+ strlen (name) + 1);
+ babl->model.component = (void *) (((char *) babl) + sizeof (BablModel));
+ babl->instance.name = (void *) (((char *) babl->model.component) + sizeof (BablComponent *) * (components));
+
babl->class_type = BABL_MODEL;
babl->instance.id = id;
babl->model.components = components;
strcpy (babl->instance.name, name);
- memcpy (babl->model.component, component, sizeof (BablComponent*)*components);
+ memcpy (babl->model.component, component, sizeof (BablComponent *) * components);
- babl->model.from = NULL;
+ babl->model.from = NULL;
return babl;
}
{
va_list varg;
Babl *babl;
- int id = 0;
- int components = 0;
- const char *arg = first_argument;
- const char *name = NULL;
+ int id = 0;
+ int components = 0;
+ const char *arg = first_argument;
+ const char *name = NULL;
BablComponent *component [BABL_MAX_COMPONENTS];
va_start (varg, first_argument);
-
+
while (1)
{
-
-
if (BABL_IS_BABL (arg))
{
- Babl *babl = (Babl*)arg;
+ Babl *babl = (Babl *) arg;
switch (babl->class_type)
{
case BABL_COMPONENT:
- component [components] = (BablComponent*) babl;
+ component [components] = (BablComponent *) babl;
components++;
- if (components>=BABL_MAX_COMPONENTS)
+ if (components >= BABL_MAX_COMPONENTS)
{
babl_log ("maximum number of components (%i) exceeded for %s",
- BABL_MAX_COMPONENTS, name);
+ BABL_MAX_COMPONENTS, name);
}
break;
+
case BABL_MODEL:
- babl_log ("submodels not handled yet");
- break;
+ babl_log ("submodels not handled yet");
+ break;
+
case BABL_TYPE:
case BABL_TYPE_INTEGER:
case BABL_TYPE_FLOAT:
case BABL_EXTENSION:
babl_log ("%s unexpected", babl_class_name (babl->class_type));
break;
+
case BABL_SKY: /* shut up compiler */
break;
}
{
name = va_arg (varg, char *);
}
-
+
else
{
babl_fatal ("unhandled argument '%s' for babl_model '%s'", arg, name);
if (!arg)
break;
}
-
- va_end (varg);
+
+ va_end (varg);
babl = model_new (create_name (name, components, component), id, components, component);
-
- {
+
+ {
Babl *ret = babl_db_insert (db, babl);
- if (ret!=babl)
- babl_free (babl);
+ if (ret != babl)
+ babl_free (babl);
return ret;
}
}
-#define TOLERANCE 0.001
+#define TOLERANCE 0.001
#define test_pixels 512
{
double *test;
int i;
-
+
srandom (20050728);
test = babl_malloc (sizeof (double) * test_pixels * 4);
for (i = 0; i < test_pixels * 4; i++)
- test [i] = ((double) random () / RAND_MAX ) * 1.4 - 0.2;
+ test [i] = ((double) random () / RAND_MAX) * 1.4 - 0.2;
return test;
}
static Babl *reference_format (void)
{
static Babl *self = NULL;
-
+
if (!self)
- self = babl_format_new (
- babl_model ("RGBA"),
- babl_type ("double"),
- babl_component ("R"),
- babl_component ("G"),
- babl_component ("B"),
- babl_component ("A"),
- NULL);
+ self = babl_format_new (
+ babl_model ("RGBA"),
+ babl_type ("double"),
+ babl_component ("R"),
+ babl_component ("G"),
+ babl_component ("B"),
+ babl_component ("A"),
+ NULL);
return self;
}
static Babl *construct_double_format (Babl *model)
{
- void *argument[42+1];
+ void *argument[42 + 1];
int args = 0;
int i;
argument[args++] = model;
argument[args++] = babl_type ("double");
- for (i=0;i<model->model.components; i++)
+ for (i = 0; i < model->model.components; i++)
{
argument[args++] = model->model.component[i];
}
argument[args++] = NULL;
-#define o(argno) argument[argno],
- return babl_format_new (o(0) o(1) o(2) o(3)
- o(4) o(5) o(6) o(7)
- o(8) o(9) o(10) o(11)
- o(12) o(13) o(14) o(15)
- o(16) o(17) o(18) o(19)
- o(20) o(21) o(22) o(23)
- o(24) o(25) o(26) o(27)
- o(28) o(29) o(30) o(31)
- o(32) o(33) o(34) o(35)
- o(36) o(37) o(38) o(39)
- o(40) o(41) o(42) NULL);
+#define o(argno) argument[argno],
+ return babl_format_new (o (0) o (1) o (2) o (3)
+ o (4) o (5) o (6) o (7)
+ o (8) o (9) o (10) o (11)
+ o (12) o (13) o (14) o (15)
+ o (16) o (17) o (18) o (19)
+ o (20) o (21) o (22) o (23)
+ o (24) o (25) o (26) o (27)
+ o (28) o (29) o (30) o (31)
+ o (32) o (33) o (34) o (35)
+ o (36) o (37) o (38) o (39)
+ o (40) o (41) o (42) NULL);
#undef o
}
-double
+double
babl_model_is_symmetric (Babl *babl)
{
double *test;
double *clipped;
void *destination;
double *transformed;
- int symmetric=1;
+ int symmetric = 1;
- Babl *ref_fmt;
- Babl *fmt;
- Babl *fish_to;
- Babl *fish_from;
+ Babl *ref_fmt;
+ Babl *fmt;
+ Babl *fish_to;
+ Babl *fish_from;
test = test_create ();
ref_fmt = reference_format ();
fmt = construct_double_format (babl);
fish_to = babl_fish_reference (ref_fmt, fmt);
fish_from = babl_fish_reference (fmt, ref_fmt);
-
- original = babl_calloc (1,64/8 * babl->model.components * test_pixels);
- clipped = babl_calloc (1,64/8 * 4 * test_pixels);
- destination = babl_calloc (1,64/8 * babl->model.components * test_pixels);
- transformed = babl_calloc (1,64/8 * 4 * test_pixels);
-
- babl_process (fish_to, test, original, test_pixels);
- babl_process (fish_from, original, clipped, test_pixels);
- babl_process (fish_to, clipped, destination, test_pixels);
+
+ original = babl_calloc (1, 64 / 8 * babl->model.components * test_pixels);
+ clipped = babl_calloc (1, 64 / 8 * 4 * test_pixels);
+ destination = babl_calloc (1, 64 / 8 * babl->model.components * test_pixels);
+ transformed = babl_calloc (1, 64 / 8 * 4 * test_pixels);
+
+ babl_process (fish_to, test, original, test_pixels);
+ babl_process (fish_from, original, clipped, test_pixels);
+ babl_process (fish_to, clipped, destination, test_pixels);
babl_process (fish_from, destination, transformed, test_pixels);
- fish_to->fish.processings-=2;
- fish_from->fish.processings-=2;
- fish_to->fish.pixels-=test_pixels*2;
- fish_from->fish.pixels -= test_pixels*2;
+ fish_to->fish.processings -= 2;
+ fish_from->fish.processings -= 2;
+ fish_to->fish.pixels -= test_pixels * 2;
+ fish_from->fish.pixels -= test_pixels * 2;
{
int i;
- int log=0;
+ int log = 0;
- for (i=0;i<test_pixels;i++)
+ for (i = 0; i < test_pixels; i++)
{
int j;
- for (j=0;j<4;j++)
- if (fabs (clipped[i*4+j] - transformed[i*4+j])>TOLERANCE)
- {
- if (!log)
- log=1;
- symmetric=0;
- }
+ for (j = 0; j < 4; j++)
+ if (fabs (clipped[i *4 + j] - transformed[i * 4 + j]) > TOLERANCE)
+ {
+ if (!log)
+ log = 1;
+ symmetric = 0;
+ }
if (log && log < 5)
{
babl_log ("%s", babl->instance.name);
- babl_log ("\ttest: %2.3f %2.3f %2.3f %2.3f", test [i*4+0],
- test [i*4+1],
- test [i*4+2],
- test [i*4+3]);
- babl_log ("\tclipped: %2.3f %2.3f %2.3f %2.3f", clipped [i*4+0],
- clipped [i*4+1],
- clipped [i*4+2],
- clipped [i*4+3]);
- babl_log ("\ttrnsfrmd: %2.3f %2.3f %2.3f %2.3f", transformed [i*4+0],
- transformed [i*4+1],
- transformed [i*4+2],
- transformed [i*4+3]);
+ babl_log ("\ttest: %2.3f %2.3f %2.3f %2.3f", test [i *4 + 0],
+ test [i * 4 + 1],
+ test [i * 4 + 2],
+ test [i * 4 + 3]);
+ babl_log ("\tclipped: %2.3f %2.3f %2.3f %2.3f", clipped [i *4 + 0],
+ clipped [i * 4 + 1],
+ clipped [i * 4 + 2],
+ clipped [i * 4 + 3]);
+ babl_log ("\ttrnsfrmd: %2.3f %2.3f %2.3f %2.3f", transformed [i *4 + 0],
+ transformed [i * 4 + 1],
+ transformed [i * 4 + 2],
+ transformed [i * 4 + 3]);
log++;
}
}
}
-
+
babl_free (original);
babl_free (clipped);
babl_free (destination);
* Boston, MA 02111-1307, USA.
*/
-#define HORIZONTAL_MIN 1
-#define HORIZONTAL_MAX 4
-#define VERTICAL_MIN 1
-#define VERTICAL_MAX 4
+#define HORIZONTAL_MIN 1
+#define HORIZONTAL_MAX 4
+#define VERTICAL_MIN 1
+#define VERTICAL_MAX 4
#include "babl-internal.h"
-static BablSampling sampling_db[(HORIZONTAL_MAX-HORIZONTAL_MIN+1)*
- (VERTICAL_MAX-VERTICAL_MIN+1)];
+static BablSampling sampling_db[(HORIZONTAL_MAX - HORIZONTAL_MIN + 1) *
+ (VERTICAL_MAX - VERTICAL_MIN + 1)];
Babl *
babl_sampling (int horizontal,
int vertical)
{
- if (vertical>=1 &&
- vertical<=4 &&
- horizontal>=1 &&
- horizontal<=4)
- return (Babl*)&sampling_db [ (vertical-1) * 4 + (horizontal-1)];
+ if (vertical >= 1 &&
+ vertical <= 4 &&
+ horizontal >= 1 &&
+ horizontal <= 4)
+ return (Babl *) &sampling_db [ (vertical - 1) * 4 + (horizontal - 1)];
else
babl_log ("babl_samping(%i,%i): arguments out of bounds",
horizontal, vertical);
}
-static int
+static int
each_babl_sampling_destroy (Babl *babl,
void *data)
{
}
void
-babl_sampling_each (BablEachFunction each_fun,
- void *user_data)
+babl_sampling_each (BablEachFunction each_fun,
+ void *user_data)
{
int horizontal;
int vertical;
- for (horizontal=HORIZONTAL_MIN; horizontal<=HORIZONTAL_MAX; horizontal++)
- for (vertical=VERTICAL_MIN; vertical<=VERTICAL_MAX; vertical++)
+ for (horizontal = HORIZONTAL_MIN; horizontal <= HORIZONTAL_MAX; horizontal++)
+ for (vertical = VERTICAL_MIN; vertical <= VERTICAL_MAX; vertical++)
{
- int index= (vertical-VERTICAL_MIN) * VERTICAL_MAX + (horizontal - HORIZONTAL_MIN);
- if (each_fun (BABL (&sampling_db[index]), user_data))
- return;
+ int index = (vertical - VERTICAL_MIN) * VERTICAL_MAX + (horizontal - HORIZONTAL_MIN);
+ if (each_fun (BABL (&sampling_db[index]), user_data))
+ return;
}
}
int horizontal;
int vertical;
- for (horizontal=HORIZONTAL_MIN; horizontal<=HORIZONTAL_MAX; horizontal++)
- for (vertical=VERTICAL_MIN; vertical<=VERTICAL_MAX; vertical++)
+ for (horizontal = HORIZONTAL_MIN; horizontal <= HORIZONTAL_MAX; horizontal++)
+ for (vertical = VERTICAL_MIN; vertical <= VERTICAL_MAX; vertical++)
{
- int index= (vertical-VERTICAL_MIN) * VERTICAL_MAX + (horizontal - HORIZONTAL_MIN);
+ int index = (vertical - VERTICAL_MIN) * VERTICAL_MAX + (horizontal - HORIZONTAL_MIN);
sampling_db[index].instance.class_type = BABL_SAMPLING;
- sampling_db[index].instance.id = 0;
- sampling_db[index].horizontal = horizontal;
- sampling_db[index].vertical = vertical;
- sampling_db[index].instance.name = sampling_db[index].name;
- sampling_db[index].name[0]='0'+horizontal;
- sampling_db[index].name[1]=':';
- sampling_db[index].name[2]='0'+vertical;
- sampling_db[index].name[3]='\0';
+ sampling_db[index].instance.id = 0;
+ sampling_db[index].horizontal = horizontal;
+ sampling_db[index].vertical = vertical;
+ sampling_db[index].instance.name = sampling_db[index].name;
+ sampling_db[index].name[0] = '0' + horizontal;
+ sampling_db[index].name[1] = ':';
+ sampling_db[index].name[2] = '0' + vertical;
+ sampling_db[index].name[3] = '\0';
}
}
#include "babl-internal.h"
static int OK;
-
+
static int
foo (Babl *babl,
void *user_data)
/* ensure that every type has reference conversions to
* and from double */
void **ptr;
- int ok;
+ int ok;
ok = 0;
if (babl->type.from)
{
ptr = (void **) babl->type.from;
- while (ptr && NULL!=*ptr)
+ while (ptr && NULL != *ptr)
{
- if (babl_conversion_destination ((Babl *)(*ptr)) == babl_type_id (BABL_DOUBLE))
+ if (babl_conversion_destination ((Babl *) (*ptr)) == babl_type_id (BABL_DOUBLE))
{
ok = 1;
break;
/* ensure that every type has reference conversions to
* and from rgba */
void **ptr;
- int ok;
+ int ok;
ok = 0;
if (babl->model.from)
{
ptr = (void **) babl->model.from;
- while (ptr && NULL!=*ptr)
+ while (ptr && NULL != *ptr)
{
- if (babl_conversion_destination ((Babl *)(*ptr)) == babl_model_id (BABL_RGBA))
+ if (babl_conversion_destination ((Babl *) (*ptr)) == babl_model_id (BABL_RGBA))
{
ok = 1;
break;
}
if (!ok)
{
- OK=0;
+ OK = 0;
babl_log ("lack of sanity! model '%s' has no conversion to 'rgba'",
babl->instance.name);
}
{
if (0 && 0 == babl->instance.id &&
babl->instance.creator &&
- !strcmp(BABL(babl->instance.creator)->instance.name, "BablBase"))
+ !strcmp (BABL (babl->instance.creator)->instance.name, "BablBase"))
{
- OK=0;
+ OK = 0;
babl_log ("%s\t'%s' has id==0",
- babl_class_name (babl->class_type), babl->instance.name);
+ babl_class_name (babl->class_type), babl->instance.name);
}
return 0;
}
#include "babl-db.h"
-static int
+static int
each_babl_type_destroy (Babl *babl,
void *data)
{
static Babl *
-type_new (const char *name,
- int id,
- int bits)
+type_new (const char *name,
+ int id,
+ int bits)
{
Babl *babl;
babl_assert (bits != 0);
babl_assert (bits % 8 == 0);
-
+
babl = babl_malloc (sizeof (BablType) + strlen (name) + 1);
- babl->instance.name = (void*)((char*) babl + sizeof (BablType));
+ babl->instance.name = (void *) ((char *) babl + sizeof (BablType));
babl->class_type = BABL_TYPE;
babl->instance.id = id;
strcpy (babl->instance.name, name);
- babl->type.bits = bits;
- babl->type.from = NULL;
+ babl->type.bits = bits;
+ babl->type.from = NULL;
return babl;
}
babl_type_new (void *first_arg,
...)
{
- va_list varg;
- Babl *babl;
- int id = 0;
- int is_integer = 0;
- int bits = 0;
- long min = 0;
- long max = 255;
- double min_val = 0.0;
- double max_val = 0.0;
-
- const char *arg=first_arg;
+ va_list varg;
+ Babl *babl;
+ int id = 0;
+ int is_integer = 0;
+ int bits = 0;
+ long min = 0;
+ long max = 255;
+ double min_val = 0.0;
+ double max_val = 0.0;
+
+ const char *arg = first_arg;
va_start (varg, first_arg);
-
+
while (1)
{
arg = va_arg (varg, char *);
if (!arg)
break;
-
+
if (BABL_IS_BABL (arg))
{
#ifdef BABL_LOG
- Babl *babl = (Babl*)arg;
+ Babl *babl = (Babl *) arg;
babl_log ("%s unexpected", babl_class_name (babl->class_type));
#endif
{
id = va_arg (varg, int);
}
-
+
else if (!strcmp (arg, "bits"))
{
bits = va_arg (varg, int);
- min = 0;
- max = 1<<bits;
+ min = 0;
+ max = 1 << bits;
}
else if (!strcmp (arg, "integer"))
{
{
max_val = va_arg (varg, double);
}
-
+
else
{
babl_fatal ("unhandled argument '%s' for format '%s'", arg, first_arg);
}
}
-
- va_end (varg);
+
+ va_end (varg);
babl = type_new (first_arg, id, bits);
- {
+ {
Babl *ret = babl_db_insert (db, babl);
- if (ret!=babl)
- babl_free (babl);
+ if (ret != babl)
+ babl_free (babl);
return ret;
}
}
-#define TOLERANCE 0.000000001
-#define samples 512
+#define TOLERANCE 0.000000001
+#define samples 512
double test[samples];
static double r_interval (double min, double max)
{
long int rand_i = random ();
- double ret;
- ret = (double) rand_i / RAND_MAX;
- ret*=(max-min);
- ret+=min;
+ double ret;
+
+ ret = (double) rand_i / RAND_MAX;
+ ret *= (max - min);
+ ret += min;
return ret;
}
static void test_init (double min, double max)
{
int i;
+
srandom (20050728);
- for (i=0;i<samples;i++)
+ for (i = 0; i < samples; i++)
{
- test [i]=r_interval(min,max);
+ test [i] = r_interval (min, max);
}
}
static Babl *double_vector_format (void)
{
static Babl *self = NULL;
-
+
if (!self)
- self = babl_format_new (
- babl_model ("Y"),
- babl_type ("double"),
- babl_component ("Y"),
- NULL);
+ self = babl_format_new (
+ babl_model ("Y"),
+ babl_type ("double"),
+ babl_component ("Y"),
+ NULL);
return self;
}
int
babl_type_is_symmetric (Babl *babl)
{
- int is_symmetrical=1;
+ int is_symmetrical = 1;
void *original;
double *clipped;
void *destination;
double *transformed;
- Babl *ref_fmt;
- Babl *fmt;
- Babl *fish_to;
- Babl *fish_from;
+ Babl *ref_fmt;
+ Babl *fmt;
+ Babl *fish_to;
+ Babl *fish_from;
test_init (0.0, 182.0);
-
+
ref_fmt = double_vector_format ();
- fmt = babl_format_new (babl_model ("Y"),
- babl,
- babl_component ("Y"),
- NULL);
+ fmt = babl_format_new (babl_model ("Y"),
+ babl,
+ babl_component ("Y"),
+ NULL);
fish_to = babl_fish_reference (ref_fmt, fmt);
fish_from = babl_fish_reference (fmt, ref_fmt);
-
- original = babl_calloc (1,babl->type.bits/8 * samples);
- clipped = babl_calloc (1,64/8 * samples);
- destination = babl_calloc (1,babl->type.bits/8 * samples);
- transformed = babl_calloc (1,64/8 * samples);
-
- babl_process (fish_to, test, original, samples);
- babl_process (fish_from, original, clipped, samples);
- babl_process (fish_to, clipped, destination, samples);
+
+ original = babl_calloc (1, babl->type.bits / 8 * samples);
+ clipped = babl_calloc (1, 64 / 8 * samples);
+ destination = babl_calloc (1, babl->type.bits / 8 * samples);
+ transformed = babl_calloc (1, 64 / 8 * samples);
+
+ babl_process (fish_to, test, original, samples);
+ babl_process (fish_from, original, clipped, samples);
+ babl_process (fish_to, clipped, destination, samples);
babl_process (fish_from, destination, transformed, samples);
- fish_from->fish.processings-=2;
- fish_to->fish.processings-=2;
- fish_from->fish.pixels -= samples*2;
- fish_to->fish.pixels -= samples*2;
+ fish_from->fish.processings -= 2;
+ fish_to->fish.processings -= 2;
+ fish_from->fish.pixels -= samples * 2;
+ fish_to->fish.pixels -= samples * 2;
{
- int cnt=0;
+ int cnt = 0;
int i;
- for (i=0;i<samples;i++)
+ for (i = 0; i < samples; i++)
{
- if (fabs (clipped[i] - transformed[i])> TOLERANCE)
+ if (fabs (clipped[i] - transformed[i]) > TOLERANCE)
{
- if (cnt++<4)
- babl_log ("%s: %f %f %f)",
- babl->instance.name, test[i], clipped[i], transformed[i]
- );
- is_symmetrical=0;
+ if (cnt++ < 4)
+ babl_log ("%s: %f %f %f)",
+ babl->instance.name, test[i], clipped[i], transformed[i]
+ );
+ is_symmetrical = 0;
}
}
}
-
+
babl_free (original);
babl_free (clipped);
babl_free (destination);
static int list_length (void **list)
{
void **ptr;
- int len=0;
+ int len = 0;
ptr = list;
- while (NULL!=*ptr)
+ while (NULL != *ptr)
{
ptr++;
len++;
babl_add_ptr_to_list (void ***list,
void *new)
{
- int orig_len=0;
+ int orig_len = 0;
if (*list)
{
orig_len = list_length (*list);
}
- *list = babl_realloc ( (*list),
- sizeof(void *) * (orig_len + 2));
+ *list = babl_realloc ((*list),
+ sizeof (void *) * (orig_len + 2));
if (!(*list))
{
- babl_fatal ("failed to realloc");
+ babl_fatal ("failed to realloc");
}
- (*list)[orig_len]=new;
- (*list)[orig_len+1]=NULL;
+ (*list)[orig_len] = new;
+ (*list)[orig_len + 1] = NULL;
}
void
-babl_list_each (void **list,
- BablEachFunction each_fun,
- void *user_data)
+babl_list_each (void **list,
+ BablEachFunction each_fun,
+ void *user_data)
{
int i;
+
if (!list)
return;
- for (i=0; i < list_length (list); i++)
+ for (i = 0; i < list_length (list); i++)
{
- if (each_fun ((Babl*) list[i], user_data))
- break;
+ if (each_fun ((Babl *) list[i], user_data))
+ break;
}
}
static struct timeval start_time;
static struct timeval measure_time;
-#define usecs(time) ((time.tv_sec-start_time.tv_sec)*1000000 + time.tv_usec)
+#define usecs(time) ((time.tv_sec - start_time.tv_sec) * 1000000 + time.tv_usec)
static void
init_ticks (void)
{
- static int done=0;
+ static int done = 0;
+
if (done)
return;
- done=1;
+ done = 1;
gettimeofday (&start_time, NULL);
}
{
init_ticks ();
gettimeofday (&measure_time, NULL);
- return usecs(measure_time) - usecs(start_time);
+ return usecs (measure_time) - usecs (start_time);
}
double
double error = 0.0;
long i;
- for (i=0; i<samples; i++)
- error += fabs (imgA[i] - imgB[i]);
+ for (i = 0; i < samples; i++)
+ error += fabs (imgA[i] - imgB[i]);
if (error >= 0.000001)
error /= samples;
#include "babl-internal.h"
-static int ref_count=0;
+static int ref_count = 0;
void
babl_init (void)
{
- if (ref_count++==0)
+ if (ref_count++ == 0)
{
babl_internal_init ();
babl_type_init ();
babl_sanity ();
babl_fish_init ();
babl_sanity ();
-
}
}
void
babl_destroy (void)
{
- if (!--ref_count)
+ if (!-- ref_count)
{
if (getenv ("BABL_STATS"))
- {
- char logfile_name[]="/tmp/babl-stats.html";
- FILE *logfile;
- logfile = fopen (logfile_name, "w");
- if (logfile)
- {
- babl_fish_stats (logfile);
- fclose (logfile);
- }
- }
-
+ {
+ char logfile_name[] = "/tmp/babl-stats.html";
+ FILE *logfile;
+ logfile = fopen (logfile_name, "w");
+ if (logfile)
+ {
+ babl_fish_stats (logfile);
+ fclose (logfile);
+ }
+ }
+
babl_extension_destroy ();
babl_fish_destroy ();
babl_conversion_destroy ();
extern int babl_hmpf_on_name_lookups;
-static void types (void);
+static void types (void);
static void models (void);
void
babl_base_init (void)
{
- babl_hmpf_on_name_lookups ++;
+ babl_hmpf_on_name_lookups++;
types ();
models ();
babl_formats_init ();
- babl_hmpf_on_name_lookups --;
+ babl_hmpf_on_name_lookups--;
}
void
static void
types (void)
{
- babl_base_type_float ();
- babl_base_type_u8 ();
- babl_base_type_u16 ();
- babl_base_type_u32 ();
+ babl_base_type_float ();
+ babl_base_type_u8 ();
+ babl_base_type_u16 ();
+ babl_base_type_u32 ();
}
/*
static void
models (void)
{
- babl_base_model_rgb ();
- babl_base_model_gray ();
+ babl_base_model_rgb ();
+ babl_base_model_gray ();
babl_base_model_ycbcr ();
}
babl_formats_init (void)
{
babl_format_new (
- babl_model_id (BABL_RGBA_GAMMA_2_2),
- babl_type_id (BABL_DOUBLE),
- babl_component_id (BABL_RED_GAMMA_2_2),
- babl_component_id (BABL_GREEN_GAMMA_2_2),
- babl_component_id (BABL_BLUE_GAMMA_2_2),
- babl_component_id (BABL_ALPHA),
- NULL);
- babl_format_new (
- babl_model_id (BABL_RGBA_GAMMA_2_2),
- babl_type_id (BABL_FLOAT),
- babl_component_id (BABL_RED_GAMMA_2_2),
- babl_component_id (BABL_GREEN_GAMMA_2_2),
- babl_component_id (BABL_BLUE_GAMMA_2_2),
- babl_component_id (BABL_ALPHA),
- NULL);
- babl_format_new (
- babl_model_id (BABL_RGBA_GAMMA_2_2),
- babl_type_id (BABL_U16),
- babl_component_id (BABL_RED_GAMMA_2_2),
- babl_component_id (BABL_GREEN_GAMMA_2_2),
- babl_component_id (BABL_BLUE_GAMMA_2_2),
- babl_component_id (BABL_ALPHA),
- NULL);
- babl_format_new (
- babl_model_id (BABL_RGBA_GAMMA_2_2),
- babl_type_id (BABL_U8),
- babl_component_id (BABL_RED_GAMMA_2_2),
- babl_component_id (BABL_GREEN_GAMMA_2_2),
- babl_component_id (BABL_BLUE_GAMMA_2_2),
- babl_component_id (BABL_ALPHA),
- NULL);
- babl_format_new (
- babl_model_id (BABL_RGBA_GAMMA_2_2_PREMULTIPLIED),
- babl_type_id (BABL_FLOAT),
- babl_component_id (BABL_RED_GAMMA_2_2_MUL_ALPHA),
- babl_component_id (BABL_GREEN_GAMMA_2_2_MUL_ALPHA),
- babl_component_id (BABL_BLUE_GAMMA_2_2_MUL_ALPHA),
- babl_component_id (BABL_ALPHA),
- NULL);
- babl_format_new (
- babl_model_id (BABL_RGBA_GAMMA_2_2_PREMULTIPLIED),
- babl_type_id (BABL_U16),
- babl_component_id (BABL_RED_GAMMA_2_2_MUL_ALPHA),
- babl_component_id (BABL_GREEN_GAMMA_2_2_MUL_ALPHA),
- babl_component_id (BABL_BLUE_GAMMA_2_2_MUL_ALPHA),
- babl_component_id (BABL_ALPHA),
- NULL);
- babl_format_new (
- babl_model_id (BABL_RGBA_GAMMA_2_2_PREMULTIPLIED),
- babl_type_id (BABL_U8),
- babl_component_id (BABL_RED_GAMMA_2_2_MUL_ALPHA),
- babl_component_id (BABL_GREEN_GAMMA_2_2_MUL_ALPHA),
- babl_component_id (BABL_BLUE_GAMMA_2_2_MUL_ALPHA),
- babl_component_id (BABL_ALPHA),
- NULL);
- babl_format_new (
- babl_model_id (BABL_RGB_GAMMA_2_2),
- babl_type_id (BABL_FLOAT),
- babl_component_id (BABL_RED_GAMMA_2_2),
- babl_component_id (BABL_GREEN_GAMMA_2_2),
- babl_component_id (BABL_BLUE_GAMMA_2_2),
- NULL);
- babl_format_new (
- babl_model_id (BABL_RGB_GAMMA_2_2),
- babl_type_id (BABL_U16),
- babl_component_id (BABL_RED_GAMMA_2_2),
- babl_component_id (BABL_GREEN_GAMMA_2_2),
- babl_component_id (BABL_BLUE_GAMMA_2_2),
- NULL);
- babl_format_new (
- babl_model_id (BABL_RGB_GAMMA_2_2),
- babl_type_id (BABL_U8),
- babl_component_id (BABL_RED_GAMMA_2_2),
- babl_component_id (BABL_GREEN_GAMMA_2_2),
- babl_component_id (BABL_BLUE_GAMMA_2_2),
- NULL);
- babl_format_new (
- babl_model_id (BABL_GRAY_GAMMA_2_2_ALPHA),
- babl_type_id (BABL_FLOAT),
- babl_component_id (BABL_LUMA),
- babl_component_id (BABL_ALPHA),
- NULL);
- babl_format_new (
- babl_model_id (BABL_GRAY_GAMMA_2_2_ALPHA_PREMULTIPLIED),
- babl_type_id (BABL_FLOAT),
- babl_component_id (BABL_LUMA_MUL_ALPHA),
- babl_component_id (BABL_ALPHA),
- NULL);
- babl_format_new (
- babl_model_id (BABL_GRAY_GAMMA_2_2),
- babl_type_id (BABL_FLOAT),
- babl_component_id (BABL_LUMA),
- NULL);
- babl_format_new (
- babl_model_id (BABL_GRAY_GAMMA_2_2_ALPHA),
- babl_type_id (BABL_U16),
- babl_component_id (BABL_LUMA),
- babl_component_id (BABL_ALPHA),
- NULL);
- babl_format_new (
- babl_model_id (BABL_GRAY_GAMMA_2_2_ALPHA_PREMULTIPLIED),
- babl_type_id (BABL_U16),
- babl_component_id (BABL_LUMA_MUL_ALPHA),
- babl_component_id (BABL_ALPHA),
- NULL);
- babl_format_new (
- babl_model_id (BABL_GRAY_GAMMA_2_2),
- babl_type_id (BABL_U16),
- babl_component_id (BABL_LUMA),
- NULL);
- babl_format_new (
- babl_model_id (BABL_GRAY_GAMMA_2_2_ALPHA),
- babl_type_id (BABL_U8),
- babl_component_id (BABL_LUMA),
- babl_component_id (BABL_ALPHA),
- NULL);
- babl_format_new (
- babl_model_id (BABL_GRAY_GAMMA_2_2_ALPHA_PREMULTIPLIED),
- babl_type_id (BABL_U8),
- babl_component_id (BABL_LUMA_MUL_ALPHA),
- babl_component_id (BABL_ALPHA),
- NULL);
- babl_format_new (
- babl_model_id (BABL_GRAY_GAMMA_2_2),
- babl_type_id (BABL_U8),
- babl_component_id (BABL_LUMA),
- NULL);
- babl_format_new (
- "name", "Y'CbCr u8",
- babl_model_id (BABL_YCBCR),
- babl_type_id (BABL_U8_LUMA),
- babl_component_id (BABL_LUMA),
- babl_type_id (BABL_U8_CHROMA),
- babl_component_id (BABL_CB),
- babl_component_id (BABL_CR),
- NULL);
- babl_format_new (
- babl_model_id (BABL_YCBCR),
- babl_type_id (BABL_FLOAT),
- babl_component_id (BABL_LUMA),
- babl_type_id (BABL_FLOAT),
- babl_component_id (BABL_CB),
- babl_component_id (BABL_CR),
- NULL);
- babl_format_new (
- babl_model_id (BABL_YCBCR_ALPHA),
- babl_type_id (BABL_FLOAT),
- babl_component_id (BABL_LUMA),
- babl_type_id (BABL_FLOAT),
- babl_component_id (BABL_CB),
- babl_component_id (BABL_CR),
- babl_component_id (BABL_ALPHA),
- NULL);
- babl_format_new (
- babl_model_id (BABL_RGBA),
- babl_type_id (BABL_FLOAT),
- babl_component_id (BABL_RED),
- babl_component_id (BABL_GREEN),
- babl_component_id (BABL_BLUE),
- babl_component_id (BABL_ALPHA),
- NULL);
- babl_format_new (
- babl_model_id (BABL_RGBA),
- babl_type_id (BABL_U16),
- babl_component_id (BABL_RED),
- babl_component_id (BABL_GREEN),
- babl_component_id (BABL_BLUE),
- babl_component_id (BABL_ALPHA),
- NULL);
- babl_format_new (
- babl_model_id (BABL_RGBA),
- babl_type_id (BABL_DOUBLE),
- babl_component_id (BABL_RED),
- babl_component_id (BABL_GREEN),
- babl_component_id (BABL_BLUE),
- babl_component_id (BABL_ALPHA),
- NULL);
- babl_format_new (
- babl_model_id (BABL_RGBA),
- babl_type_id (BABL_U8),
- babl_component_id (BABL_RED),
- babl_component_id (BABL_GREEN),
- babl_component_id (BABL_BLUE),
- babl_component_id (BABL_ALPHA),
- NULL);
- babl_format_new (
- babl_model_id (BABL_RGBA_PREMULTIPLIED),
- babl_type_id (BABL_FLOAT),
- babl_component_id (BABL_RED_MUL_ALPHA),
- babl_component_id (BABL_GREEN_MUL_ALPHA),
- babl_component_id (BABL_BLUE_MUL_ALPHA),
- babl_component_id (BABL_ALPHA),
- NULL);
- babl_format_new (
- babl_model_id (BABL_RGBA_PREMULTIPLIED),
- babl_type_id (BABL_U16),
- babl_component_id (BABL_RED_MUL_ALPHA),
- babl_component_id (BABL_GREEN_MUL_ALPHA),
- babl_component_id (BABL_BLUE_MUL_ALPHA),
- babl_component_id (BABL_ALPHA),
- NULL);
- babl_format_new (
- babl_model_id (BABL_RGBA_PREMULTIPLIED),
- babl_type_id (BABL_U8),
- babl_component_id (BABL_RED_MUL_ALPHA),
- babl_component_id (BABL_GREEN_MUL_ALPHA),
- babl_component_id (BABL_BLUE_MUL_ALPHA),
- babl_component_id (BABL_ALPHA),
- NULL);
- babl_format_new (
- babl_model_id (BABL_RGB),
- babl_type_id (BABL_FLOAT),
- babl_component_id (BABL_RED),
- babl_component_id (BABL_GREEN),
- babl_component_id (BABL_BLUE),
- NULL);
- babl_format_new (
- babl_model_id (BABL_RGB),
- babl_type_id (BABL_U16),
- babl_component_id (BABL_RED),
- babl_component_id (BABL_GREEN),
- babl_component_id (BABL_BLUE),
- NULL);
- babl_format_new (
- babl_model_id (BABL_RGB),
- babl_type_id (BABL_U8),
- babl_component_id (BABL_RED),
- babl_component_id (BABL_GREEN),
- babl_component_id (BABL_BLUE),
- NULL);
- babl_format_new (
- babl_model_id (BABL_GRAY_ALPHA),
- babl_type_id (BABL_FLOAT),
- babl_component_id (BABL_LUMINANCE),
- babl_component_id (BABL_ALPHA),
- NULL);
- babl_format_new (
- babl_model_id (BABL_GRAY_ALPHA_PREMULTIPLIED),
- babl_type_id (BABL_FLOAT),
- babl_component_id (BABL_LUMINANCE_MUL_ALPHA),
- babl_component_id (BABL_ALPHA),
- NULL);
- babl_format_new (
- babl_model_id (BABL_GRAY),
- babl_type_id (BABL_FLOAT),
- babl_component_id (BABL_LUMINANCE),
- NULL);
- babl_format_new (
- babl_model_id (BABL_GRAY_ALPHA),
- babl_type_id (BABL_U16),
- babl_component_id (BABL_LUMINANCE),
- babl_component_id (BABL_ALPHA),
- NULL);
- babl_format_new (
- babl_model_id (BABL_GRAY_ALPHA_PREMULTIPLIED),
- babl_type_id (BABL_U16),
- babl_component_id (BABL_LUMINANCE_MUL_ALPHA),
- babl_component_id (BABL_ALPHA),
- NULL);
- babl_format_new (
- babl_model_id (BABL_GRAY),
- babl_type_id (BABL_U16),
- babl_component_id (BABL_LUMINANCE),
- NULL);
- babl_format_new (
- babl_model_id (BABL_GRAY_ALPHA),
- babl_type_id (BABL_U8),
- babl_component_id (BABL_LUMINANCE),
- babl_component_id (BABL_ALPHA),
- NULL);
- babl_format_new (
- babl_model_id (BABL_GRAY_ALPHA_PREMULTIPLIED),
- babl_type_id (BABL_U8),
- babl_component_id (BABL_LUMINANCE_MUL_ALPHA),
- babl_component_id (BABL_ALPHA),
- NULL);
- babl_format_new (
- babl_model_id (BABL_GRAY),
- babl_type_id (BABL_U8),
- babl_component_id (BABL_LUMINANCE),
- NULL);
+ babl_model_id (BABL_RGBA_GAMMA_2_2),
+ babl_type_id (BABL_DOUBLE),
+ babl_component_id (BABL_RED_GAMMA_2_2),
+ babl_component_id (BABL_GREEN_GAMMA_2_2),
+ babl_component_id (BABL_BLUE_GAMMA_2_2),
+ babl_component_id (BABL_ALPHA),
+ NULL);
+ babl_format_new (
+ babl_model_id (BABL_RGBA_GAMMA_2_2),
+ babl_type_id (BABL_FLOAT),
+ babl_component_id (BABL_RED_GAMMA_2_2),
+ babl_component_id (BABL_GREEN_GAMMA_2_2),
+ babl_component_id (BABL_BLUE_GAMMA_2_2),
+ babl_component_id (BABL_ALPHA),
+ NULL);
+ babl_format_new (
+ babl_model_id (BABL_RGBA_GAMMA_2_2),
+ babl_type_id (BABL_U16),
+ babl_component_id (BABL_RED_GAMMA_2_2),
+ babl_component_id (BABL_GREEN_GAMMA_2_2),
+ babl_component_id (BABL_BLUE_GAMMA_2_2),
+ babl_component_id (BABL_ALPHA),
+ NULL);
+ babl_format_new (
+ babl_model_id (BABL_RGBA_GAMMA_2_2),
+ babl_type_id (BABL_U8),
+ babl_component_id (BABL_RED_GAMMA_2_2),
+ babl_component_id (BABL_GREEN_GAMMA_2_2),
+ babl_component_id (BABL_BLUE_GAMMA_2_2),
+ babl_component_id (BABL_ALPHA),
+ NULL);
+ babl_format_new (
+ babl_model_id (BABL_RGBA_GAMMA_2_2_PREMULTIPLIED),
+ babl_type_id (BABL_FLOAT),
+ babl_component_id (BABL_RED_GAMMA_2_2_MUL_ALPHA),
+ babl_component_id (BABL_GREEN_GAMMA_2_2_MUL_ALPHA),
+ babl_component_id (BABL_BLUE_GAMMA_2_2_MUL_ALPHA),
+ babl_component_id (BABL_ALPHA),
+ NULL);
+ babl_format_new (
+ babl_model_id (BABL_RGBA_GAMMA_2_2_PREMULTIPLIED),
+ babl_type_id (BABL_U16),
+ babl_component_id (BABL_RED_GAMMA_2_2_MUL_ALPHA),
+ babl_component_id (BABL_GREEN_GAMMA_2_2_MUL_ALPHA),
+ babl_component_id (BABL_BLUE_GAMMA_2_2_MUL_ALPHA),
+ babl_component_id (BABL_ALPHA),
+ NULL);
+ babl_format_new (
+ babl_model_id (BABL_RGBA_GAMMA_2_2_PREMULTIPLIED),
+ babl_type_id (BABL_U8),
+ babl_component_id (BABL_RED_GAMMA_2_2_MUL_ALPHA),
+ babl_component_id (BABL_GREEN_GAMMA_2_2_MUL_ALPHA),
+ babl_component_id (BABL_BLUE_GAMMA_2_2_MUL_ALPHA),
+ babl_component_id (BABL_ALPHA),
+ NULL);
+ babl_format_new (
+ babl_model_id (BABL_RGB_GAMMA_2_2),
+ babl_type_id (BABL_FLOAT),
+ babl_component_id (BABL_RED_GAMMA_2_2),
+ babl_component_id (BABL_GREEN_GAMMA_2_2),
+ babl_component_id (BABL_BLUE_GAMMA_2_2),
+ NULL);
+ babl_format_new (
+ babl_model_id (BABL_RGB_GAMMA_2_2),
+ babl_type_id (BABL_U16),
+ babl_component_id (BABL_RED_GAMMA_2_2),
+ babl_component_id (BABL_GREEN_GAMMA_2_2),
+ babl_component_id (BABL_BLUE_GAMMA_2_2),
+ NULL);
+ babl_format_new (
+ babl_model_id (BABL_RGB_GAMMA_2_2),
+ babl_type_id (BABL_U8),
+ babl_component_id (BABL_RED_GAMMA_2_2),
+ babl_component_id (BABL_GREEN_GAMMA_2_2),
+ babl_component_id (BABL_BLUE_GAMMA_2_2),
+ NULL);
+ babl_format_new (
+ babl_model_id (BABL_GRAY_GAMMA_2_2_ALPHA),
+ babl_type_id (BABL_FLOAT),
+ babl_component_id (BABL_LUMA),
+ babl_component_id (BABL_ALPHA),
+ NULL);
+ babl_format_new (
+ babl_model_id (BABL_GRAY_GAMMA_2_2_ALPHA_PREMULTIPLIED),
+ babl_type_id (BABL_FLOAT),
+ babl_component_id (BABL_LUMA_MUL_ALPHA),
+ babl_component_id (BABL_ALPHA),
+ NULL);
+ babl_format_new (
+ babl_model_id (BABL_GRAY_GAMMA_2_2),
+ babl_type_id (BABL_FLOAT),
+ babl_component_id (BABL_LUMA),
+ NULL);
+ babl_format_new (
+ babl_model_id (BABL_GRAY_GAMMA_2_2_ALPHA),
+ babl_type_id (BABL_U16),
+ babl_component_id (BABL_LUMA),
+ babl_component_id (BABL_ALPHA),
+ NULL);
+ babl_format_new (
+ babl_model_id (BABL_GRAY_GAMMA_2_2_ALPHA_PREMULTIPLIED),
+ babl_type_id (BABL_U16),
+ babl_component_id (BABL_LUMA_MUL_ALPHA),
+ babl_component_id (BABL_ALPHA),
+ NULL);
+ babl_format_new (
+ babl_model_id (BABL_GRAY_GAMMA_2_2),
+ babl_type_id (BABL_U16),
+ babl_component_id (BABL_LUMA),
+ NULL);
+ babl_format_new (
+ babl_model_id (BABL_GRAY_GAMMA_2_2_ALPHA),
+ babl_type_id (BABL_U8),
+ babl_component_id (BABL_LUMA),
+ babl_component_id (BABL_ALPHA),
+ NULL);
+ babl_format_new (
+ babl_model_id (BABL_GRAY_GAMMA_2_2_ALPHA_PREMULTIPLIED),
+ babl_type_id (BABL_U8),
+ babl_component_id (BABL_LUMA_MUL_ALPHA),
+ babl_component_id (BABL_ALPHA),
+ NULL);
+ babl_format_new (
+ babl_model_id (BABL_GRAY_GAMMA_2_2),
+ babl_type_id (BABL_U8),
+ babl_component_id (BABL_LUMA),
+ NULL);
+ babl_format_new (
+ "name", "Y'CbCr u8",
+ babl_model_id (BABL_YCBCR),
+ babl_type_id (BABL_U8_LUMA),
+ babl_component_id (BABL_LUMA),
+ babl_type_id (BABL_U8_CHROMA),
+ babl_component_id (BABL_CB),
+ babl_component_id (BABL_CR),
+ NULL);
+ babl_format_new (
+ babl_model_id (BABL_YCBCR),
+ babl_type_id (BABL_FLOAT),
+ babl_component_id (BABL_LUMA),
+ babl_type_id (BABL_FLOAT),
+ babl_component_id (BABL_CB),
+ babl_component_id (BABL_CR),
+ NULL);
+ babl_format_new (
+ babl_model_id (BABL_YCBCR_ALPHA),
+ babl_type_id (BABL_FLOAT),
+ babl_component_id (BABL_LUMA),
+ babl_type_id (BABL_FLOAT),
+ babl_component_id (BABL_CB),
+ babl_component_id (BABL_CR),
+ babl_component_id (BABL_ALPHA),
+ NULL);
+ babl_format_new (
+ babl_model_id (BABL_RGBA),
+ babl_type_id (BABL_FLOAT),
+ babl_component_id (BABL_RED),
+ babl_component_id (BABL_GREEN),
+ babl_component_id (BABL_BLUE),
+ babl_component_id (BABL_ALPHA),
+ NULL);
+ babl_format_new (
+ babl_model_id (BABL_RGBA),
+ babl_type_id (BABL_U16),
+ babl_component_id (BABL_RED),
+ babl_component_id (BABL_GREEN),
+ babl_component_id (BABL_BLUE),
+ babl_component_id (BABL_ALPHA),
+ NULL);
+ babl_format_new (
+ babl_model_id (BABL_RGBA),
+ babl_type_id (BABL_DOUBLE),
+ babl_component_id (BABL_RED),
+ babl_component_id (BABL_GREEN),
+ babl_component_id (BABL_BLUE),
+ babl_component_id (BABL_ALPHA),
+ NULL);
+ babl_format_new (
+ babl_model_id (BABL_RGBA),
+ babl_type_id (BABL_U8),
+ babl_component_id (BABL_RED),
+ babl_component_id (BABL_GREEN),
+ babl_component_id (BABL_BLUE),
+ babl_component_id (BABL_ALPHA),
+ NULL);
+ babl_format_new (
+ babl_model_id (BABL_RGBA_PREMULTIPLIED),
+ babl_type_id (BABL_FLOAT),
+ babl_component_id (BABL_RED_MUL_ALPHA),
+ babl_component_id (BABL_GREEN_MUL_ALPHA),
+ babl_component_id (BABL_BLUE_MUL_ALPHA),
+ babl_component_id (BABL_ALPHA),
+ NULL);
+ babl_format_new (
+ babl_model_id (BABL_RGBA_PREMULTIPLIED),
+ babl_type_id (BABL_U16),
+ babl_component_id (BABL_RED_MUL_ALPHA),
+ babl_component_id (BABL_GREEN_MUL_ALPHA),
+ babl_component_id (BABL_BLUE_MUL_ALPHA),
+ babl_component_id (BABL_ALPHA),
+ NULL);
+ babl_format_new (
+ babl_model_id (BABL_RGBA_PREMULTIPLIED),
+ babl_type_id (BABL_U8),
+ babl_component_id (BABL_RED_MUL_ALPHA),
+ babl_component_id (BABL_GREEN_MUL_ALPHA),
+ babl_component_id (BABL_BLUE_MUL_ALPHA),
+ babl_component_id (BABL_ALPHA),
+ NULL);
+ babl_format_new (
+ babl_model_id (BABL_RGB),
+ babl_type_id (BABL_FLOAT),
+ babl_component_id (BABL_RED),
+ babl_component_id (BABL_GREEN),
+ babl_component_id (BABL_BLUE),
+ NULL);
+ babl_format_new (
+ babl_model_id (BABL_RGB),
+ babl_type_id (BABL_U16),
+ babl_component_id (BABL_RED),
+ babl_component_id (BABL_GREEN),
+ babl_component_id (BABL_BLUE),
+ NULL);
+ babl_format_new (
+ babl_model_id (BABL_RGB),
+ babl_type_id (BABL_U8),
+ babl_component_id (BABL_RED),
+ babl_component_id (BABL_GREEN),
+ babl_component_id (BABL_BLUE),
+ NULL);
+ babl_format_new (
+ babl_model_id (BABL_GRAY_ALPHA),
+ babl_type_id (BABL_FLOAT),
+ babl_component_id (BABL_LUMINANCE),
+ babl_component_id (BABL_ALPHA),
+ NULL);
+ babl_format_new (
+ babl_model_id (BABL_GRAY_ALPHA_PREMULTIPLIED),
+ babl_type_id (BABL_FLOAT),
+ babl_component_id (BABL_LUMINANCE_MUL_ALPHA),
+ babl_component_id (BABL_ALPHA),
+ NULL);
+ babl_format_new (
+ babl_model_id (BABL_GRAY),
+ babl_type_id (BABL_FLOAT),
+ babl_component_id (BABL_LUMINANCE),
+ NULL);
+ babl_format_new (
+ babl_model_id (BABL_GRAY_ALPHA),
+ babl_type_id (BABL_U16),
+ babl_component_id (BABL_LUMINANCE),
+ babl_component_id (BABL_ALPHA),
+ NULL);
+ babl_format_new (
+ babl_model_id (BABL_GRAY_ALPHA_PREMULTIPLIED),
+ babl_type_id (BABL_U16),
+ babl_component_id (BABL_LUMINANCE_MUL_ALPHA),
+ babl_component_id (BABL_ALPHA),
+ NULL);
+ babl_format_new (
+ babl_model_id (BABL_GRAY),
+ babl_type_id (BABL_U16),
+ babl_component_id (BABL_LUMINANCE),
+ NULL);
+ babl_format_new (
+ babl_model_id (BABL_GRAY_ALPHA),
+ babl_type_id (BABL_U8),
+ babl_component_id (BABL_LUMINANCE),
+ babl_component_id (BABL_ALPHA),
+ NULL);
+ babl_format_new (
+ babl_model_id (BABL_GRAY_ALPHA_PREMULTIPLIED),
+ babl_type_id (BABL_U8),
+ babl_component_id (BABL_LUMINANCE_MUL_ALPHA),
+ babl_component_id (BABL_ALPHA),
+ NULL);
+ babl_format_new (
+ babl_model_id (BABL_GRAY),
+ babl_type_id (BABL_U8),
+ babl_component_id (BABL_LUMINANCE),
+ NULL);
/* overriding name, since the generated name would be wrong due
* to differing types
*/
babl_format_new (
- "name", "Y'CbCr u8",
- babl_model_id (BABL_YCBCR),
- babl_type_id (BABL_U8_LUMA),
- babl_component_id (BABL_LUMA),
- babl_type_id (BABL_U8_CHROMA),
- babl_component_id (BABL_CB),
- babl_component_id (BABL_CR),
- NULL);
- babl_format_new (
- babl_model_id (BABL_YCBCR),
- babl_type_id (BABL_FLOAT),
- babl_component_id (BABL_LUMA),
- babl_type_id (BABL_FLOAT),
- babl_component_id (BABL_CB),
- babl_component_id (BABL_CR),
- NULL);
- babl_format_new (
- babl_model_id (BABL_YCBCR_ALPHA),
- babl_type_id (BABL_FLOAT),
- babl_component_id (BABL_LUMA),
- babl_type_id (BABL_FLOAT),
- babl_component_id (BABL_CB),
- babl_component_id (BABL_CR),
- babl_component_id (BABL_ALPHA),
- NULL);
+ "name", "Y'CbCr u8",
+ babl_model_id (BABL_YCBCR),
+ babl_type_id (BABL_U8_LUMA),
+ babl_component_id (BABL_LUMA),
+ babl_type_id (BABL_U8_CHROMA),
+ babl_component_id (BABL_CB),
+ babl_component_id (BABL_CR),
+ NULL);
+ babl_format_new (
+ babl_model_id (BABL_YCBCR),
+ babl_type_id (BABL_FLOAT),
+ babl_component_id (BABL_LUMA),
+ babl_type_id (BABL_FLOAT),
+ babl_component_id (BABL_CB),
+ babl_component_id (BABL_CR),
+ NULL);
+ babl_format_new (
+ babl_model_id (BABL_YCBCR_ALPHA),
+ babl_type_id (BABL_FLOAT),
+ babl_component_id (BABL_LUMA),
+ babl_type_id (BABL_FLOAT),
+ babl_component_id (BABL_CB),
+ babl_component_id (BABL_CR),
+ babl_component_id (BABL_ALPHA),
+ NULL);
}
#include "util.h"
-static void components (void);
-static void models (void);
-static void conversions (void);
-static void formats (void);
+static void components (void);
+static void models (void);
+static void conversions (void);
+static void formats (void);
void
babl_base_model_cmyk (void)
{
- components ();
- models ();
- conversions ();
- formats ();
+ components ();
+ models ();
+ conversions ();
+ formats ();
}
static void
components (void)
{
- babl_component_new (
- "cyan",
- "id", BABL_CYAN,
- NULL);
+ babl_component_new (
+ "cyan",
+ "id", BABL_CYAN,
+ NULL);
babl_component_new (
- "yellow",
- "id", BABL_YELLOW,
- NULL);
+ "yellow",
+ "id", BABL_YELLOW,
+ NULL);
babl_component_new (
- "magenta",
- "id", BABL_MAGENTA,
- NULL);
+ "magenta",
+ "id", BABL_MAGENTA,
+ NULL);
babl_component_new (
- "key",
- "id", BABL_KEY,
- NULL);
+ "key",
+ "id", BABL_KEY,
+ NULL);
}
static void
static long
rgb_to_cmyk (void *src,
void *dst,
- long n)
+ long n)
{
while (n--)
{
- double red = ((double*)src)[0];
- double green = ((double*)src)[1];
- double blue = ((double*)src)[2];
+ double red = ((double *) src)[0];
+ double green = ((double *) src)[1];
+ double blue = ((double *) src)[2];
double cyan, magenta, yellow, key;
yellow = 1.0 - blue;
key = 1.0;
- if (cyan < key) key = cyan;
+ if (cyan < key) key = cyan;
if (magenta < key) key = magenta;
- if (yellow < key) key = yellow;
+ if (yellow < key) key = yellow;
key *= pullout;
if (key < 1.0)
{
- cyan = (cyan - key) / (1.0 -key);
- magenta = (magenta - key) / (1.0 -key);
- yellow = (yellow - key) / (1.0 -key);
+ cyan = (cyan - key) / (1.0 - key);
+ magenta = (magenta - key) / (1.0 - key);
+ yellow = (yellow - key) / (1.0 - key);
}
else
{
yellow = 0.0;
}
- ((double*)dst)[0] = cyan;
- ((double*)dst)[1] = magenta;
- ((double*)dst)[2] = yellow;
- ((double*)dst)[3] = key;
+ ((double *) dst)[0] = cyan;
+ ((double *) dst)[1] = magenta;
+ ((double *) dst)[2] = yellow;
+ ((double *) dst)[3] = key;
- src+=4*sizeof(double);
- dst+=4*sizeof(double)
+ src += 4 * sizeof (double);
+ dst += 4 * sizeof (double)
}
return n;
}
-static long
+static long
cmyk_to_rgb (void *src,
void *dst,
long n)
{
while (n--)
{
- double cyan = ((double*)src)[0];
- double yellow = ((double*)src)[1];
- double magenta = ((double*)src)[2];
- double key = ((double*)src)[3];
+ double cyan = ((double *) src)[0];
+ double yellow = ((double *) src)[1];
+ double magenta = ((double *) src)[2];
+ double key = ((double *) src)[3];
double red, green, blue;
if (key < 1.0)
{
- cyan = cyan * (1.0 - key) + key;
+ cyan = cyan * (1.0 - key) + key;
magenta = magenta * (1.0 - key) + key;
- yellow = yellow * (1.0 - key) + key;
+ yellow = yellow * (1.0 - key) + key;
}
else
{
green = 1.0 - magenta;
blue = 1.0 - yellow;
- ((double*)dst)[0] = red;
- ((double*)dst)[1] = green;
- ((double*)dst)[2] = blue;
+ ((double *) dst)[0] = red;
+ ((double *) dst)[1] = green;
+ ((double *) dst)[2] = blue;
- ((double*)dst)[3] = 1.0;
+ ((double *) dst)[3] = 1.0;
- src+=4*sizeof(double);
- dst+=4*sizeof(double)
+ src += 4 * sizeof (double);
+ dst += 4 * sizeof (double)
}
return n;
}
{
babl_conversion_new (
"babl-base: rgba to cmyk",
- "source", babl_model_id (BABL_RGBA),
+ "source", babl_model_id (BABL_RGBA),
"destination", babl_model_id (BABL_CMYK),
- "linear", rgb_to_cmyk,
+ "linear", rgb_to_cmyk,
NULL
);
babl_conversion_new (
"babl-base: cmyk to rgba",
- "source", babl_model_id (BABL_CMYK),
+ "source", babl_model_id (BABL_CMYK),
"destination", babl_model_id (BABL_RGBA),
- "linear", cmyk_to_rgb,
+ "linear", cmyk_to_rgb,
NULL
);
}
#include "math.h"
#include "babl-base.h"
-static void components (void);
-static void models (void);
+static void components (void);
+static void models (void);
static void conversions (void);
void babl_base_model_gray (void)
{
- components ();
- models ();
+ components ();
+ models ();
conversions ();
}
components (void)
{
babl_component_new (
- "Y",
- "id", BABL_LUMINANCE,
- "luma",
- NULL);
+ "Y",
+ "id", BABL_LUMINANCE,
+ "luma",
+ NULL);
babl_component_new (
- "Ya",
- "id", BABL_LUMINANCE_MUL_ALPHA,
- "luma",
- NULL);
+ "Ya",
+ "id", BABL_LUMINANCE_MUL_ALPHA,
+ "luma",
+ NULL);
babl_component_new (
- "Y'",
- "id", BABL_LUMA,
- "luma",
- NULL);
+ "Y'",
+ "id", BABL_LUMA,
+ "luma",
+ NULL);
babl_component_new (
- "Y'a",
- "id", BABL_LUMA_MUL_ALPHA,
- "luma",
- NULL);
+ "Y'a",
+ "id", BABL_LUMA_MUL_ALPHA,
+ "luma",
+ NULL);
}
static void
double red, green, blue;
double luminance, alpha;
- red = ((double *)src)[0];
- green = ((double *)src)[1];
- blue = ((double *)src)[2];
- alpha = ((double *)src)[3];
+ red = ((double *) src)[0];
+ green = ((double *) src)[1];
+ blue = ((double *) src)[2];
+ alpha = ((double *) src)[3];
- luminance = red * RGB_LUMINANCE_RED +
- green * RGB_LUMINANCE_GREEN +
- blue * RGB_LUMINANCE_BLUE;
+ luminance = red * RGB_LUMINANCE_RED +
+ green * RGB_LUMINANCE_GREEN +
+ blue * RGB_LUMINANCE_BLUE;
- ((double*)dst)[0] = luminance;
- ((double*)dst)[1] = alpha;
+ ((double *) dst)[0] = luminance;
+ ((double *) dst)[1] = alpha;
src += sizeof (double) * 4;
dst += sizeof (double) * 2;
double red, green, blue;
double luminance, alpha;
- red = ((double *)src)[0];
- green = ((double *)src)[1];
- blue = ((double *)src)[2];
- alpha = ((double *)src)[3];
+ red = ((double *) src)[0];
+ green = ((double *) src)[1];
+ blue = ((double *) src)[2];
+ alpha = ((double *) src)[3];
- luminance = red * RGB_LUMINANCE_RED +
- green * RGB_LUMINANCE_GREEN +
- blue * RGB_LUMINANCE_BLUE;
+ luminance = red * RGB_LUMINANCE_RED +
+ green * RGB_LUMINANCE_GREEN +
+ blue * RGB_LUMINANCE_BLUE;
- ((double*)dst)[0] = luminance;
+ ((double *) dst)[0] = luminance;
src += sizeof (double) * 4;
dst += sizeof (double) * 1;
red = *(double *) src[0];
green = *(double *) src[1];
blue = *(double *) src[2];
- if (src_bands>3)
- alpha = *(double *)src[3];
+ if (src_bands > 3)
+ alpha = *(double *) src[3];
else
alpha = 1.0;
- luminance = red * RGB_LUMINANCE_RED +
- green * RGB_LUMINANCE_GREEN +
- blue * RGB_LUMINANCE_BLUE;
- *(double*)dst[0] = linear_to_gamma_2_2 (luminance);
+ luminance = red * RGB_LUMINANCE_RED +
+ green * RGB_LUMINANCE_GREEN +
+ blue * RGB_LUMINANCE_BLUE;
+ *(double *) dst[0] = linear_to_gamma_2_2 (luminance);
- if (dst_bands==2)
- *(double*)dst[1] = alpha;
+ if (dst_bands == 2)
+ *(double *) dst[1] = alpha;
BABL_PLANAR_STEP
}
double red, green, blue;
double alpha;
- luminance = gamma_2_2_to_linear (*(double *)src[0]);
+ luminance = gamma_2_2_to_linear (*(double *) src[0]);
red = luminance;
green = luminance;
blue = luminance;
if (src_bands > 1)
- alpha = *(double *)src[1];
+ alpha = *(double *) src[1];
else
- alpha = 1.0;
+ alpha = 1.0;
- *(double*)dst[0] = red;
- *(double*)dst[1] = green;
- *(double*)dst[2] = blue;
+ *(double *) dst[0] = red;
+ *(double *) dst[1] = green;
+ *(double *) dst[2] = blue;
- if (dst_bands>3)
- *(double*)dst[3] = alpha;
+ if (dst_bands > 3)
+ *(double *) dst[3] = alpha;
BABL_PLANAR_STEP
}
double red, green, blue;
double alpha;
- luminance = ((double *)src)[0];
- alpha = ((double *)src)[1];
+ luminance = ((double *) src)[0];
+ alpha = ((double *) src)[1];
red = luminance;
green = luminance;
blue = luminance;
- ((double*)dst)[0] = red;
- ((double*)dst)[1] = green;
- ((double*)dst)[2] = blue;
- ((double*)dst)[3] = alpha;
+ ((double *) dst)[0] = red;
+ ((double *) dst)[1] = green;
+ ((double *) dst)[2] = blue;
+ ((double *) dst)[3] = alpha;
- src += sizeof(double)*2;
- dst += sizeof(double)*4;
+ src += sizeof (double) * 2;
+ dst += sizeof (double) * 4;
}
return n;
}
double luminance;
double red, green, blue;
- luminance = ((double *)src)[0];
+ luminance = ((double *) src)[0];
red = luminance;
green = luminance;
blue = luminance;
- ((double*)dst)[0] = red;
- ((double*)dst)[1] = green;
- ((double*)dst)[2] = blue;
- ((double*)dst)[3] = 1.0;
+ ((double *) dst)[0] = red;
+ ((double *) dst)[1] = green;
+ ((double *) dst)[2] = blue;
+ ((double *) dst)[3] = 1.0;
- src += sizeof(double)*1;
- dst += sizeof(double)*4;
+ src += sizeof (double) * 1;
+ dst += sizeof (double) * 4;
}
return n;
}
while (n--)
{
- double luminance = *(double *)src[0];
- double alpha = *(double *)src[1];
+ double luminance = *(double *) src[0];
+ double alpha = *(double *) src[1];
if (alpha > 0.00001)
{
{
luminance = 0.0;
}
-
- *(double*)dst[0] = luminance;
- *(double*)dst[1] = luminance;
- *(double*)dst[2] = luminance;
- *(double*)dst[3] = alpha;
+
+ *(double *) dst[0] = luminance;
+ *(double *) dst[1] = luminance;
+ *(double *) dst[2] = luminance;
+ *(double *) dst[3] = alpha;
BABL_PLANAR_STEP
}
return n;
while (n--)
{
- double red = *(double *)src[0];
- double green = *(double *)src[1];
- double blue = *(double *)src[2];
- double alpha = *(double *)src[3];
+ double red = *(double *) src[0];
+ double green = *(double *) src[1];
+ double blue = *(double *) src[2];
+ double alpha = *(double *) src[3];
double luminance;
- luminance = red * RGB_LUMINANCE_RED +
- green * RGB_LUMINANCE_GREEN +
- blue * RGB_LUMINANCE_BLUE;
+ luminance = red * RGB_LUMINANCE_RED +
+ green * RGB_LUMINANCE_GREEN +
+ blue * RGB_LUMINANCE_BLUE;
luminance *= alpha;
-
- *(double*)dst[0] = luminance;
- *(double*)dst[1] = alpha;
+
+ *(double *) dst[0] = luminance;
+ *(double *) dst[1] = alpha;
BABL_PLANAR_STEP
}
return n;
while (n--)
{
double alpha;
- int band;
+ int band;
- alpha = *(double *)src[src_bands-1];
- for (band=0; band<src_bands-1;band++)
+ alpha = *(double *) src[src_bands - 1];
+ for (band = 0; band < src_bands - 1; band++)
{
- *(double*)dst[band] = *(double*) src[band] * alpha;
+ *(double *) dst[band] = *(double *) src[band] * alpha;
}
- *(double*)dst[dst_bands-1] = alpha;
+ *(double *) dst[dst_bands - 1] = alpha;
BABL_PLANAR_STEP
}
while (n--)
{
double alpha;
- int band;
+ int band;
- alpha = *(double *)src[src_bands-1];
- for (band=0; band<src_bands-1;band++)
+ alpha = *(double *) src[src_bands - 1];
+ for (band = 0; band < src_bands - 1; band++)
{
- if (alpha>0.001)
+ if (alpha > 0.001)
{
- *(double*)dst[band] = *(double*) src[band] / alpha;
+ *(double *) dst[band] = *(double *) src[band] / alpha;
}
else
{
- *(double*)dst[band] = 0.001;
+ *(double *) dst[band] = 0.001;
}
}
- *(double*)dst[dst_bands-1] = alpha;
+ *(double *) dst[dst_bands - 1] = alpha;
BABL_PLANAR_STEP
}
{
while (n--)
{
- double red = ((double*)src)[0];
- double green = ((double*)src)[1];
- double blue = ((double*)src)[2];
- double alpha = ((double*)src)[3];
+ double red = ((double *) src)[0];
+ double green = ((double *) src)[1];
+ double blue = ((double *) src)[2];
+ double alpha = ((double *) src)[3];
double luminance;
double luma;
-
- luminance = red * RGB_LUMINANCE_RED +
- green * RGB_LUMINANCE_GREEN +
- blue * RGB_LUMINANCE_BLUE;
+
+ luminance = red * RGB_LUMINANCE_RED +
+ green * RGB_LUMINANCE_GREEN +
+ blue * RGB_LUMINANCE_BLUE;
luma = linear_to_gamma_2_2 (luminance);
- ((double*)dst)[0] = luma * alpha;
- ((double*)dst)[1] = alpha;
+ ((double *) dst)[0] = luma * alpha;
+ ((double *) dst)[1] = alpha;
- src+=4 * sizeof (double);
- dst+=2 * sizeof (double);
+ src += 4 * sizeof (double);
+ dst += 2 * sizeof (double);
}
return n;
}
static long
gray_gamma_2_2_premultiplied2rgba (char *src,
char *dst,
- long n)
+ long n)
{
while (n--)
{
- double luma = ((double*) src)[0];
- double alpha = ((double*) src)[1];
+ double luma = ((double *) src)[0];
+ double alpha = ((double *) src)[1];
double luminance;
- luma = luma / alpha;
+ luma = luma / alpha;
luminance = gamma_2_2_to_linear (luma);
-
- ((double*)dst)[0] = luminance;
- ((double*)dst)[1] = luminance;
- ((double*)dst)[2] = luminance;
- ((double*)dst)[3] = alpha;
-
- src+=2 * sizeof (double);
- dst+=4 * sizeof (double);
+
+ ((double *) dst)[0] = luminance;
+ ((double *) dst)[1] = luminance;
+ ((double *) dst)[2] = luminance;
+ ((double *) dst)[3] = alpha;
+
+ src += 2 * sizeof (double);
+ dst += 4 * sizeof (double);
}
return n;
}
babl_conversion_new (
babl_model_id (BABL_GRAY_GAMMA_2_2),
babl_model_id (BABL_RGBA),
- "planar", gray_2_2_to_rgb,
+ "planar", gray_2_2_to_rgb,
NULL
);
babl_conversion_new (
babl_model_id (BABL_RGBA),
babl_model_id (BABL_GRAY_GAMMA_2_2),
- "planar", rgb_to_gray_2_2,
+ "planar", rgb_to_gray_2_2,
NULL
);
babl_conversion_new (
babl_model_id (BABL_GRAY_GAMMA_2_2_ALPHA),
babl_model_id (BABL_RGBA),
- "planar", gray_2_2_to_rgb,
+ "planar", gray_2_2_to_rgb,
NULL
);
babl_conversion_new (
babl_model_id (BABL_RGBA),
babl_model_id (BABL_GRAY_GAMMA_2_2_ALPHA),
- "planar", rgb_to_gray_2_2,
+ "planar", rgb_to_gray_2_2,
NULL
);
babl_conversion_new (
babl_model_id (BABL_GRAY_GAMMA_2_2_ALPHA_PREMULTIPLIED),
babl_model_id (BABL_RGBA),
- "linear", gray_gamma_2_2_premultiplied2rgba,
+ "linear", gray_gamma_2_2_premultiplied2rgba,
NULL
);
babl_conversion_new (
babl_model_id (BABL_RGBA),
babl_model_id (BABL_GRAY_GAMMA_2_2_ALPHA_PREMULTIPLIED),
- "linear", rgba2gray_gamma_2_2_premultiplied,
+ "linear", rgba2gray_gamma_2_2_premultiplied,
NULL
);
babl_conversion_new (
babl_model_id (BABL_GRAY),
babl_model_id (BABL_RGBA),
- "linear", gray_to_rgba,
+ "linear", gray_to_rgba,
NULL
);
babl_conversion_new (
babl_model_id (BABL_GRAY_ALPHA),
babl_model_id (BABL_RGBA),
- "linear", graya_to_rgba,
+ "linear", graya_to_rgba,
NULL
);
babl_conversion_new (
babl_model_id (BABL_RGBA),
babl_model_id (BABL_GRAY_ALPHA),
- "linear", rgba_to_graya,
+ "linear", rgba_to_graya,
NULL
);
babl_conversion_new (
babl_model_id (BABL_RGBA),
babl_model_id (BABL_GRAY),
- "linear", rgba_to_gray,
+ "linear", rgba_to_gray,
NULL
);
babl_conversion_new (
babl_model_id (BABL_GRAY_ALPHA),
babl_model_id (BABL_GRAY_ALPHA_PREMULTIPLIED),
- "planar", non_premultiplied_to_premultiplied,
+ "planar", non_premultiplied_to_premultiplied,
NULL
);
babl_conversion_new (
babl_model_id (BABL_GRAY_ALPHA_PREMULTIPLIED),
babl_model_id (BABL_GRAY_ALPHA),
- "planar", premultiplied_to_non_premultiplied,
+ "planar", premultiplied_to_non_premultiplied,
NULL
);
babl_conversion_new (
babl_model_id (BABL_GRAY_ALPHA_PREMULTIPLIED),
babl_model_id (BABL_RGBA),
- "planar", gray_alpha_premultiplied_to_rgba,
+ "planar", gray_alpha_premultiplied_to_rgba,
NULL
);
babl_conversion_new (
babl_model_id (BABL_RGBA),
babl_model_id (BABL_GRAY_ALPHA_PREMULTIPLIED),
- "planar", rgba_to_gray_alpha_premultiplied,
+ "planar", rgba_to_gray_alpha_premultiplied,
NULL
);
}
#include "util.h"
#include "babl-base.h"
-static void models (void);
-static void components (void);
-static void conversions (void);
-static void formats (void);
+static void models (void);
+static void components (void);
+static void conversions (void);
+static void formats (void);
void
babl_base_model_rgb (void)
{
- components ();
- models ();
- conversions ();
- formats ();
+ components ();
+ models ();
+ conversions ();
+ formats ();
}
static void
components (void)
{
-
-
-
babl_component_new (
"Ra",
- "id", BABL_RED_MUL_ALPHA,
+ "id", BABL_RED_MUL_ALPHA,
"luma",
"chroma",
"alpha",
NULL);
babl_component_new (
"Ga",
- "id", BABL_GREEN_MUL_ALPHA,
+ "id", BABL_GREEN_MUL_ALPHA,
"luma",
"chroma",
"alpha",
NULL);
babl_component_new (
"Ba",
- "id", BABL_BLUE_MUL_ALPHA,
+ "id", BABL_BLUE_MUL_ALPHA,
"luma",
"chroma",
"alpha",
babl_component_new (
"R'",
- "id", BABL_RED_GAMMA_2_2,
+ "id", BABL_RED_GAMMA_2_2,
"luma",
"chroma",
NULL);
babl_component_new (
"G'",
- "id", BABL_GREEN_GAMMA_2_2,
- "luma",
- "chroma",
- NULL);
-
+ "id", BABL_GREEN_GAMMA_2_2,
+ "luma",
+ "chroma",
+ NULL);
+
babl_component_new (
"B'",
- "id", BABL_BLUE_GAMMA_2_2,
- "luma",
- "chroma",
- NULL);
+ "id", BABL_BLUE_GAMMA_2_2,
+ "luma",
+ "chroma",
+ NULL);
babl_component_new (
"R'a",
- "id", BABL_RED_GAMMA_2_2_MUL_ALPHA,
+ "id", BABL_RED_GAMMA_2_2_MUL_ALPHA,
"luma",
"chroma",
NULL);
babl_component_new (
"G'a",
- "id", BABL_GREEN_GAMMA_2_2_MUL_ALPHA,
- "luma",
- "chroma",
- NULL);
-
+ "id", BABL_GREEN_GAMMA_2_2_MUL_ALPHA,
+ "luma",
+ "chroma",
+ NULL);
+
babl_component_new (
"B'a",
- "id", BABL_BLUE_GAMMA_2_2_MUL_ALPHA,
- "luma",
- "chroma",
- NULL);
+ "id", BABL_BLUE_GAMMA_2_2_MUL_ALPHA,
+ "luma",
+ "chroma",
+ NULL);
}
static void
models (void)
{
-
babl_model_new (
"id", BABL_RGB,
babl_component_id (BABL_RED),
babl_component_id (BABL_BLUE),
NULL);
- babl_model_new (
+ babl_model_new (
"id", BABL_RGBA_PREMULTIPLIED,
babl_component_id (BABL_RED_MUL_ALPHA),
babl_component_id (BABL_GREEN_MUL_ALPHA),
int *dst_pitch,
long samples)
{
- long n=samples;
+ long n = samples;
+
BABL_PLANAR_SANITY
while (n--)
{
int i;
- for (i=0;i<dst_bands;i++)
+ for (i = 0; i < dst_bands; i++)
{
double foo;
- if (i<src_bands)
+ if (i < src_bands)
foo = *(double *) src[i];
else
foo = 1.0;
- *(double*)dst[i] = foo;
+ *(double *) dst[i] = foo;
}
BABL_PLANAR_STEP
int *dst_pitch,
long samples)
{
- long n=samples;
+ long n = samples;
+
BABL_PLANAR_SANITY
while (n--)
{
int band;
- for (band=0;band<3;band++)
- *(double*)dst[band] = linear_to_gamma_2_2 (*(double*) src[band]);
- for (;band<dst_bands;band++)
- *(double*)dst[band] = *(double*) src[band];
+ for (band = 0; band < 3; band++)
+ *(double *) dst[band] = linear_to_gamma_2_2 (*(double *) src[band]);
+ for (; band < dst_bands; band++)
+ *(double *) dst[band] = *(double *) src[band];
BABL_PLANAR_STEP
}
int *dst_pitch,
long samples)
{
- long n=samples;
+ long n = samples;
+
BABL_PLANAR_SANITY
while (n--)
{
int band;
- for (band=0;band<3;band++)
+ for (band = 0; band < 3; band++)
{
- *(double*)dst[band] = gamma_2_2_to_linear (*(double*) src[band]);
+ *(double *) dst[band] = gamma_2_2_to_linear (*(double *) src[band]);
}
- for (;band<dst_bands;band++)
+ for (; band < dst_bands; band++)
{
- if (band<src_bands)
- *(double*)dst[band] = *(double*) src[band];
+ if (band < src_bands)
+ *(double *) dst[band] = *(double *) src[band];
else
- *(double*)dst[band] = 1.0;
+ *(double *) dst[band] = 1.0;
}
BABL_PLANAR_STEP
}
int *dst_pitch,
long samples)
{
- long n=samples;
+ long n = samples;
+
BABL_PLANAR_SANITY
while (n--)
{
double alpha;
- int band;
+ int band;
- alpha = *(double *)src[src_bands-1];
- for (band=0; band<src_bands-1;band++)
+ alpha = *(double *) src[src_bands - 1];
+ for (band = 0; band < src_bands - 1; band++)
{
- *(double*)dst[band] = *(double*) src[band] * alpha;
+ *(double *) dst[band] = *(double *) src[band] * alpha;
}
- *(double*)dst[dst_bands-1] = alpha;
+ *(double *) dst[dst_bands - 1] = alpha;
BABL_PLANAR_STEP
}
int *dst_pitch,
long samples)
{
- long n=samples;
+ long n = samples;
+
BABL_PLANAR_SANITY
while (n--)
{
double alpha;
- int band;
+ int band;
- alpha = *(double *)src[src_bands-1];
- for (band=0; band<src_bands-1;band++)
+ alpha = *(double *) src[src_bands - 1];
+ for (band = 0; band < src_bands - 1; band++)
{
- if (alpha>0.001)
+ if (alpha > 0.001)
{
- *(double*)dst[band] = *(double*) src[band] / alpha;
+ *(double *) dst[band] = *(double *) src[band] / alpha;
}
else
{
- *(double*)dst[band] = 0.00;
+ *(double *) dst[band] = 0.00;
}
}
- *(double*)dst[dst_bands-1] = alpha;
+ *(double *) dst[dst_bands - 1] = alpha;
BABL_PLANAR_STEP
}
char *dst,
long samples)
{
- long n=samples;
+ long n = samples;
+
while (n--)
{
- double alpha = ((double*)src)[3];
- ((double*)dst)[0] = linear_to_gamma_2_2 (((double*) src)[0]) * alpha;
- ((double*)dst)[1] = linear_to_gamma_2_2 (((double*) src)[1]) * alpha;
- ((double*)dst)[2] = linear_to_gamma_2_2 (((double*) src)[2]) * alpha;
- ((double*)dst)[3] = alpha;
- src+=4 * sizeof (double);
- dst+=4 * sizeof (double);
+ double alpha = ((double *) src)[3];
+ ((double *) dst)[0] = linear_to_gamma_2_2 (((double *) src)[0]) * alpha;
+ ((double *) dst)[1] = linear_to_gamma_2_2 (((double *) src)[1]) * alpha;
+ ((double *) dst)[2] = linear_to_gamma_2_2 (((double *) src)[2]) * alpha;
+ ((double *) dst)[3] = alpha;
+ src += 4 * sizeof (double);
+ dst += 4 * sizeof (double);
}
return samples;
}
static long
rgba_gamma_2_2_premultiplied2rgba (char *src,
char *dst,
- long samples)
+ long samples)
{
- long n=samples;
+ long n = samples;
+
while (n--)
{
- double alpha = ((double*) src)[3];
- if (alpha > 0.0001)
+ double alpha = ((double *) src)[3];
+ if (alpha > 0.0001)
{
- ((double*)dst)[0] = gamma_2_2_to_linear (((double*) src)[0] / alpha);
- ((double*)dst)[1] = gamma_2_2_to_linear (((double*) src)[1] / alpha);
- ((double*)dst)[2] = gamma_2_2_to_linear (((double*) src)[2] / alpha);
+ ((double *) dst)[0] = gamma_2_2_to_linear (((double *) src)[0] / alpha);
+ ((double *) dst)[1] = gamma_2_2_to_linear (((double *) src)[1] / alpha);
+ ((double *) dst)[2] = gamma_2_2_to_linear (((double *) src)[2] / alpha);
}
else
{
- ((double*)dst)[0] = 0.0;
- ((double*)dst)[1] = 0.0;
- ((double*)dst)[2] = 0.0;
+ ((double *) dst)[0] = 0.0;
+ ((double *) dst)[1] = 0.0;
+ ((double *) dst)[2] = 0.0;
}
- ((double*)dst)[3] = alpha;
+ ((double *) dst)[3] = alpha;
- src+=4 * sizeof (double);
- dst+=4 * sizeof (double);
+ src += 4 * sizeof (double);
+ dst += 4 * sizeof (double);
}
return samples;
}
char *dst,
long samples)
{
- long n=samples;
+ long n = samples;
+
while (n--)
{
- double alpha = ((double*)src)[3];
- ((double*)dst)[0] = linear_to_gamma_2_2 (((double*) src)[0]);
- ((double*)dst)[1] = linear_to_gamma_2_2 (((double*) src)[1]);
- ((double*)dst)[2] = linear_to_gamma_2_2 (((double*) src)[2]);
- ((double*)dst)[3] = alpha;
- src+=4 * sizeof (double);
- dst+=4 * sizeof (double);
+ double alpha = ((double *) src)[3];
+ ((double *) dst)[0] = linear_to_gamma_2_2 (((double *) src)[0]);
+ ((double *) dst)[1] = linear_to_gamma_2_2 (((double *) src)[1]);
+ ((double *) dst)[2] = linear_to_gamma_2_2 (((double *) src)[2]);
+ ((double *) dst)[3] = alpha;
+ src += 4 * sizeof (double);
+ dst += 4 * sizeof (double);
}
return samples;
}
char *dst,
long samples)
{
- long n=samples;
-
+ long n = samples;
+
while (n--)
{
- double alpha = ((double*) src)[3];
- ((double*)dst)[0] = gamma_2_2_to_linear (((double*) src)[0]);
- ((double*)dst)[1] = gamma_2_2_to_linear (((double*) src)[1]);
- ((double*)dst)[2] = gamma_2_2_to_linear (((double*) src)[2]);
- ((double*)dst)[3] = alpha;
-
- src+=4 * sizeof (double);
- dst+=4 * sizeof (double);
+ double alpha = ((double *) src)[3];
+ ((double *) dst)[0] = gamma_2_2_to_linear (((double *) src)[0]);
+ ((double *) dst)[1] = gamma_2_2_to_linear (((double *) src)[1]);
+ ((double *) dst)[2] = gamma_2_2_to_linear (((double *) src)[2]);
+ ((double *) dst)[3] = alpha;
+
+ src += 4 * sizeof (double);
+ dst += 4 * sizeof (double);
}
return samples;
}
babl_conversion_new (
babl_model_id (BABL_RGBA),
babl_model_id (BABL_RGBA),
- "planar", copy_strip_1,
+ "planar", copy_strip_1,
NULL
);
babl_conversion_new (
babl_model_id (BABL_RGB),
babl_model_id (BABL_RGBA),
- "planar", copy_strip_1,
+ "planar", copy_strip_1,
NULL
);
babl_conversion_new (
babl_model_id (BABL_RGBA),
babl_model_id (BABL_RGB),
- "planar", copy_strip_1,
+ "planar", copy_strip_1,
NULL
);
babl_conversion_new (
babl_model_id (BABL_RGBA),
babl_model_id (BABL_RGBA_PREMULTIPLIED),
- "planar", non_premultiplied_to_premultiplied,
+ "planar", non_premultiplied_to_premultiplied,
NULL
);
babl_conversion_new (
babl_model_id (BABL_RGBA_PREMULTIPLIED),
babl_model_id (BABL_RGBA),
- "planar", premultiplied_to_non_premultiplied,
+ "planar", premultiplied_to_non_premultiplied,
NULL
);
babl_conversion_new (
babl_model_id (BABL_RGBA),
babl_model_id (BABL_RGB_GAMMA_2_2),
- "planar", g3_gamma_2_2,
+ "planar", g3_gamma_2_2,
NULL
);
babl_conversion_new (
babl_model_id (BABL_RGB_GAMMA_2_2),
babl_model_id (BABL_RGBA),
- "planar", g3_inv_gamma_2_2,
+ "planar", g3_inv_gamma_2_2,
NULL
);
babl_model_id (BABL_RGBA),
"linear", rgba_gamma_2_2_premultiplied2rgba,
NULL);
-
}
static void
formats (void)
{
- babl_format_new (
+ babl_format_new (
//"name", "srgb",
"id", BABL_SRGB,
- babl_model_id (BABL_RGB_GAMMA_2_2),
- babl_type_id (BABL_U8),
+ babl_model_id (BABL_RGB_GAMMA_2_2),
+ babl_type_id (BABL_U8),
babl_component_id (BABL_RED_GAMMA_2_2),
babl_component_id (BABL_GREEN_GAMMA_2_2),
babl_component_id (BABL_BLUE_GAMMA_2_2),
babl_format_new (
"id", BABL_SRGBA,
- babl_model_id (BABL_RGBA_GAMMA_2_2),
- babl_type_id (BABL_U8),
+ babl_model_id (BABL_RGBA_GAMMA_2_2),
+ babl_type_id (BABL_U8),
babl_component_id (BABL_RED_GAMMA_2_2),
babl_component_id (BABL_GREEN_GAMMA_2_2),
babl_component_id (BABL_BLUE_GAMMA_2_2),
NULL);
babl_format_new (
- "id", BABL_RGBA_FLOAT,
- babl_model_id (BABL_RGBA),
- babl_type_id (BABL_FLOAT),
- babl_component_id (BABL_RED),
- babl_component_id (BABL_GREEN),
+ "id", BABL_RGBA_FLOAT,
+ babl_model_id (BABL_RGBA),
+ babl_type_id (BABL_FLOAT),
+ babl_component_id (BABL_RED),
+ babl_component_id (BABL_GREEN),
babl_component_id (BABL_BLUE),
babl_component_id (BABL_ALPHA),
NULL);
babl_format_new (
"id", BABL_RGB_FLOAT,
- babl_model_id (BABL_RGB),
- babl_type_id (BABL_FLOAT),
- babl_component_id (BABL_RED),
- babl_component_id (BABL_GREEN),
+ babl_model_id (BABL_RGB),
+ babl_type_id (BABL_FLOAT),
+ babl_component_id (BABL_RED),
+ babl_component_id (BABL_GREEN),
babl_component_id (BABL_BLUE),
NULL);
#ifdef XXXX
babl_format_new (
"id", BABL_RGB565,
- babl_model_id (BABL_RGB),
- babl_component_id (BABL_RED),
- babl_component_id (BABL_GREEN),
+ babl_model_id (BABL_RGB),
+ babl_component_id (BABL_RED),
+ babl_component_id (BABL_GREEN),
babl_component_id (BABL_BLUE),
);
#include "util.h"
-static void components (void);
-static void models (void);
-static void conversions (void);
+static void components (void);
+static void models (void);
+static void conversions (void);
static void formats (void);
void
babl_base_model_ycbcr (void)
{
- components ();
- models ();
- conversions ();
- formats ();
+ components ();
+ models ();
+ conversions ();
+ formats ();
}
static void
components (void)
{
babl_component_new (
- "Cb",
- "id", BABL_CB,
- "chroma",
- NULL);
+ "Cb",
+ "id", BABL_CB,
+ "chroma",
+ NULL);
babl_component_new (
- "Cr",
- "id", BABL_CR,
- "chroma",
- NULL);
+ "Cr",
+ "id", BABL_CR,
+ "chroma",
+ NULL);
}
static void
{
while (n--)
{
- double red = ((double*)src)[0];
- double green = ((double*)src)[1];
- double blue = ((double*)src)[2];
- double alpha = ((double*)src)[3];
+ double red = ((double *) src)[0];
+ double green = ((double *) src)[1];
+ double blue = ((double *) src)[2];
+ double alpha = ((double *) src)[3];
double luminance, cb, cr;
red = linear_to_gamma_2_2 (red);
green = linear_to_gamma_2_2 (green);
blue = linear_to_gamma_2_2 (blue);
-
- luminance = 0.299 * red +0.587 * green +0.114 * blue;
- cb = -0.168736 * red -0.331264 * green +0.5 * blue;
- cr = 0.5 * red -0.418688 * green -0.081312 * blue;
- ((double*)dst)[0] = luminance;
- ((double*)dst)[1] = cb;
- ((double*)dst)[2] = cr;
- ((double*)dst)[3] = alpha;
+ luminance = 0.299 * red + 0.587 * green + 0.114 * blue;
+ cb = -0.168736 * red - 0.331264 * green + 0.5 * blue;
+ cr = 0.5 * red - 0.418688 * green - 0.081312 * blue;
+
+ ((double *) dst)[0] = luminance;
+ ((double *) dst)[1] = cb;
+ ((double *) dst)[2] = cr;
+ ((double *) dst)[3] = alpha;
src += sizeof (double) * 4;
dst += sizeof (double) * 4;
{
while (n--)
{
- double red = ((double*)src)[0];
- double green = ((double*)src)[1];
- double blue = ((double*)src)[2];
+ double red = ((double *) src)[0];
+ double green = ((double *) src)[1];
+ double blue = ((double *) src)[2];
double luminance, cb, cr;
red = linear_to_gamma_2_2 (red);
green = linear_to_gamma_2_2 (green);
blue = linear_to_gamma_2_2 (blue);
-
- luminance = 0.299 * red +0.587 * green +0.114 * blue;
- cb = -0.168736 * red -0.331264 * green +0.5 * blue;
- cr = 0.5 * red -0.418688 * green -0.081312 * blue;
- ((double*)dst)[0] = luminance;
- ((double*)dst)[1] = cb;
- ((double*)dst)[2] = cr;
+ luminance = 0.299 * red + 0.587 * green + 0.114 * blue;
+ cb = -0.168736 * red - 0.331264 * green + 0.5 * blue;
+ cr = 0.5 * red - 0.418688 * green - 0.081312 * blue;
+
+ ((double *) dst)[0] = luminance;
+ ((double *) dst)[1] = cb;
+ ((double *) dst)[2] = cr;
src += sizeof (double) * 4;
dst += sizeof (double) * 3;
{
while (n--)
{
- double luminance = ((double*)src)[0];
- double cb = ((double*)src)[1];
- double cr = ((double*)src)[2];
- double alpha = ((double*)src)[3];
+ double luminance = ((double *) src)[0];
+ double cb = ((double *) src)[1];
+ double cr = ((double *) src)[2];
+ double alpha = ((double *) src)[3];
double red, green, blue;
- red = 1.0 * luminance + 0.0 * cb + 1.40200 * cr;
- green = 1.0 * luminance - 0.344136 * cb - 0.71414136 * cr;
- blue = 1.0 * luminance + 1.772 * cb + 0.0 * cr;
+ red = 1.0 * luminance + 0.0 * cb + 1.40200 * cr;
+ green = 1.0 * luminance - 0.344136 * cb - 0.71414136 * cr;
+ blue = 1.0 * luminance + 1.772 * cb + 0.0 * cr;
red = gamma_2_2_to_linear (red);
green = gamma_2_2_to_linear (green);
blue = gamma_2_2_to_linear (blue);
- ((double*)dst)[0] = red;
- ((double*)dst)[1] = green;
- ((double*)dst)[2] = blue;
- ((double*)dst)[3] = alpha;
+ ((double *) dst)[0] = red;
+ ((double *) dst)[1] = green;
+ ((double *) dst)[2] = blue;
+ ((double *) dst)[3] = alpha;
src += sizeof (double) * 4;
dst += sizeof (double) * 4;
{
while (n--)
{
- double luminance = ((double*)src)[0];
- double cb = ((double*)src)[1];
- double cr = ((double*)src)[2];
+ double luminance = ((double *) src)[0];
+ double cb = ((double *) src)[1];
+ double cr = ((double *) src)[2];
double red, green, blue;
- red = 1.0 * luminance + 0.0 * cb + 1.40200 * cr;
- green = 1.0 * luminance - 0.344136 * cb - 0.71414136 * cr;
- blue = 1.0 * luminance + 1.772 * cb + 0.0 * cr;
+ red = 1.0 * luminance + 0.0 * cb + 1.40200 * cr;
+ green = 1.0 * luminance - 0.344136 * cb - 0.71414136 * cr;
+ blue = 1.0 * luminance + 1.772 * cb + 0.0 * cr;
red = gamma_2_2_to_linear (red);
green = gamma_2_2_to_linear (green);
blue = gamma_2_2_to_linear (blue);
- ((double*)dst)[0] = red;
- ((double*)dst)[1] = green;
- ((double*)dst)[2] = blue;
- ((double*)dst)[3] = 1.0;
+ ((double *) dst)[0] = red;
+ ((double *) dst)[1] = green;
+ ((double *) dst)[2] = blue;
+ ((double *) dst)[3] = 1.0;
src += sizeof (double) * 3;
dst += sizeof (double) * 4;
babl_conversion_new (
babl_model_id (BABL_RGBA),
babl_model_id (BABL_YCBCR),
- "linear", rgba_to_ycbcr,
+ "linear", rgba_to_ycbcr,
NULL
);
babl_conversion_new (
babl_model_id (BABL_YCBCR),
babl_model_id (BABL_RGBA),
- "linear", ycbcr_to_rgba,
+ "linear", ycbcr_to_rgba,
NULL
);
babl_conversion_new (
babl_model_id (BABL_RGBA),
babl_model_id (BABL_YCBCR_ALPHA),
- "linear", rgba_to_ycbcra,
+ "linear", rgba_to_ycbcra,
NULL
);
babl_conversion_new (
babl_model_id (BABL_YCBCR_ALPHA),
babl_model_id (BABL_RGBA),
- "linear", ycbcra_to_rgba,
+ "linear", ycbcra_to_rgba,
NULL
);
}
formats (void)
{
babl_format_new (
- "name", "Y'CbCr u8",
- "id", BABL_YCBCR420,
+ "name", "Y'CbCr u8",
+ "id", BABL_YCBCR420,
"planar",
- babl_model_id (BABL_YCBCR),
- babl_type_id (BABL_U8_LUMA),
- babl_sampling (1, 1),
+ babl_model_id (BABL_YCBCR),
+ babl_type_id (BABL_U8_LUMA),
+ babl_sampling (1, 1),
babl_component_id (BABL_LUMA),
- babl_type_id (BABL_U8_CHROMA),
- babl_sampling (2, 2),
- babl_component_id (BABL_CB),
- babl_sampling (2, 2),
+ babl_type_id (BABL_U8_CHROMA),
+ babl_sampling (2, 2),
+ babl_component_id (BABL_CB),
+ babl_sampling (2, 2),
babl_component_id (BABL_CR),
NULL);
return;
babl_format_new (
- "name", "y'cbcr420",
- "id", BABL_YCBCR420,
+ "name", "y'cbcr420",
+ "id", BABL_YCBCR420,
"planar",
- babl_model_id (BABL_YCBCR),
- babl_type_id (BABL_U8_LUMA),
- babl_sampling (1, 1),
+ babl_model_id (BABL_YCBCR),
+ babl_type_id (BABL_U8_LUMA),
+ babl_sampling (1, 1),
babl_component_id (BABL_LUMA),
- babl_type_id (BABL_U8_CHROMA),
- babl_sampling (2, 2),
- babl_component_id (BABL_CB),
- babl_sampling (2, 2),
+ babl_type_id (BABL_U8_CHROMA),
+ babl_sampling (2, 2),
+ babl_component_id (BABL_CB),
+ babl_sampling (2, 2),
babl_component_id (BABL_CR),
NULL);
-
+
babl_format_new (
- "name", "y'cbcr422",
- "id", BABL_YCBCR422,
+ "name", "y'cbcr422",
+ "id", BABL_YCBCR422,
"planar",
- babl_model_id (BABL_YCBCR),
- babl_type_id (BABL_U8_LUMA),
- babl_sampling (1, 1),
+ babl_model_id (BABL_YCBCR),
+ babl_type_id (BABL_U8_LUMA),
+ babl_sampling (1, 1),
babl_component_id (BABL_LUMA),
- babl_type_id (BABL_U8_CHROMA),
- babl_sampling (2, 1),
- babl_component_id (BABL_CB),
- babl_sampling (2, 1),
+ babl_type_id (BABL_U8_CHROMA),
+ babl_sampling (2, 1),
+ babl_component_id (BABL_CB),
+ babl_sampling (2, 1),
babl_component_id (BABL_CR),
NULL);
babl_format_new (
- "name", "y'cbcr411",
- "id", BABL_YCBCR411,
+ "name", "y'cbcr411",
+ "id", BABL_YCBCR411,
"planar",
- babl_model_id (BABL_YCBCR),
- babl_type_id (BABL_U8_LUMA),
- babl_sampling (1, 1),
+ babl_model_id (BABL_YCBCR),
+ babl_type_id (BABL_U8_LUMA),
+ babl_sampling (1, 1),
babl_component_id (BABL_LUMA),
- babl_type_id (BABL_U8_CHROMA),
- babl_sampling (4, 1),
- babl_component_id (BABL_CB),
- babl_sampling (4, 1),
+ babl_type_id (BABL_U8_CHROMA),
+ babl_sampling (4, 1),
+ babl_component_id (BABL_CB),
+ babl_sampling (4, 1),
babl_component_id (BABL_CR),
NULL);
}
while (n--)
{
(*(float *) dst) = (*(double *) src);
- dst += dst_pitch;
- src += src_pitch;
+ dst += dst_pitch;
+ src += src_pitch;
}
return n;
}
while (n--)
{
(*(double *) dst) = (*(float *) src);
- dst += dst_pitch;
- src += src_pitch;
+ dst += dst_pitch;
+ src += src_pitch;
}
return n;
}
{
babl_type_new (
"float",
- "id", BABL_FLOAT,
+ "id", BABL_FLOAT,
"bits", 32,
NULL);
static inline long
-convert_double_u16_scaled (double min_val,
- double max_val,
- uint16_t min,
- uint16_t max,
- char *src,
- char *dst,
- int src_pitch,
- int dst_pitch,
- long n)
+convert_double_u16_scaled (double min_val,
+ double max_val,
+ uint16_t min,
+ uint16_t max,
+ char *src,
+ char *dst,
+ int src_pitch,
+ int dst_pitch,
+ long n)
{
while (n--)
{
else if (dval > max_val)
u16val = max;
else
- u16val = rint((dval-min_val) / (max_val-min_val) * (max-min) + min);
+ u16val = rint ((dval - min_val) / (max_val - min_val) * (max - min) + min);
*(uint16_t *) dst = u16val;
- dst += dst_pitch;
- src += src_pitch;
+ dst += dst_pitch;
+ src += src_pitch;
}
return n;
}
static inline long
-convert_u16_double_scaled (double min_val,
- double max_val,
- uint16_t min,
- uint16_t max,
- char *src,
- char *dst,
- int src_pitch,
- int dst_pitch,
- long n)
+convert_u16_double_scaled (double min_val,
+ double max_val,
+ uint16_t min,
+ uint16_t max,
+ char *src,
+ char *dst,
+ int src_pitch,
+ int dst_pitch,
+ long n)
{
while (n--)
{
- int u16val = *(uint16_t*) src;
+ int u16val = *(uint16_t *) src;
double dval;
if (u16val < min)
else if (u16val > max)
dval = max_val;
else
- dval = (u16val-min) / (double)(max-min) * (max_val-min_val) + min_val;
+ dval = (u16val - min) / (double) (max - min) * (max_val - min_val) + min_val;
(*(double *) dst) = dval;
- dst += dst_pitch;
- src += src_pitch;
+ dst += dst_pitch;
+ src += src_pitch;
}
return n;
}
#define MAKE_CONVERSIONS(name, min_val, max_val, min, max) \
-static long \
-convert_##name##_double (void *src, \
- void *dst, \
- int src_pitch, \
- int dst_pitch, \
- long n) \
-{ \
- return convert_u16_double_scaled (min_val, max_val, min, max, \
- src, dst, src_pitch, dst_pitch, n);\
-} \
-static long \
-convert_double_##name (void *src, \
- void *dst, \
- int src_pitch, \
- int dst_pitch, \
- long n) \
-{ \
- return convert_double_u16_scaled (min_val, max_val, min, max, \
- src, dst, src_pitch, dst_pitch, n);\
-}
+ static long \
+ convert_ ## name ## _double (void *src, \
+ void *dst, \
+ int src_pitch, \
+ int dst_pitch, \
+ long n) \
+ { \
+ return convert_u16_double_scaled (min_val, max_val, min, max, \
+ src, dst, src_pitch, dst_pitch, n); \
+ } \
+ static long \
+ convert_double_ ## name (void *src, \
+ void *dst, \
+ int src_pitch, \
+ int dst_pitch, \
+ long n) \
+ { \
+ return convert_double_u16_scaled (min_val, max_val, min, max, \
+ src, dst, src_pitch, dst_pitch, n); \
+ }
-MAKE_CONVERSIONS(u16,0.0,1.0,0,UINT16_MAX);
+MAKE_CONVERSIONS (u16, 0.0, 1.0, 0, UINT16_MAX);
void
babl_base_type_u16 (void)
{
babl_type_new (
"u16",
- "id", BABL_U16,
+ "id", BABL_U16,
"bits", 16,
NULL);
#include "babl-base.h"
static inline long
-convert_double_u32_scaled (double min_val,
- double max_val,
- uint32_t min,
- uint32_t max,
- char *src,
- char *dst,
- int src_pitch,
- int dst_pitch,
- long n)
+convert_double_u32_scaled (double min_val,
+ double max_val,
+ uint32_t min,
+ uint32_t max,
+ char *src,
+ char *dst,
+ int src_pitch,
+ int dst_pitch,
+ long n)
{
while (n--)
{
else if (dval > max_val)
u32val = max;
else
- u32val = rint ((dval-min_val) / (max_val-min_val) * (max-min) + min);
+ u32val = rint ((dval - min_val) / (max_val - min_val) * (max - min) + min);
*(uint32_t *) dst = u32val;
- dst += dst_pitch;
- src += src_pitch;
+ dst += dst_pitch;
+ src += src_pitch;
}
return n;
}
static inline long
-convert_u32_double_scaled (double min_val,
- double max_val,
- uint32_t min,
- uint32_t max,
- char *src,
- char *dst,
- int src_pitch,
- int dst_pitch,
- long n)
+convert_u32_double_scaled (double min_val,
+ double max_val,
+ uint32_t min,
+ uint32_t max,
+ char *src,
+ char *dst,
+ int src_pitch,
+ int dst_pitch,
+ long n)
{
while (n--)
{
- int u32val = *(uint32_t*) src;
+ int u32val = *(uint32_t *) src;
double dval;
if (u32val < min)
else if (u32val > max)
dval = max_val;
else
- dval = (u32val-min) / (double)(max-min) * (max_val-min_val) + min_val;
+ dval = (u32val - min) / (double) (max - min) * (max_val - min_val) + min_val;
(*(double *) dst) = dval;
- dst += dst_pitch;
- src += src_pitch;
+ dst += dst_pitch;
+ src += src_pitch;
}
return n;
}
#define MAKE_CONVERSIONS(name, min_val, max_val, min, max) \
-static long \
-convert_##name##_double (void *src, \
- void *dst, \
- int src_pitch, \
- int dst_pitch, \
- long n) \
-{ \
- return convert_u32_double_scaled (min_val, max_val, min, max, \
- src, dst, src_pitch, dst_pitch, n);\
-} \
-static long \
-convert_double_##name (void *src, \
- void *dst, \
- int src_pitch, \
- int dst_pitch, \
- long n) \
-{ \
- return convert_double_u32_scaled (min_val, max_val, min, max, \
- src, dst, src_pitch, dst_pitch, n);\
-}
+ static long \
+ convert_ ## name ## _double (void *src, \
+ void *dst, \
+ int src_pitch, \
+ int dst_pitch, \
+ long n) \
+ { \
+ return convert_u32_double_scaled (min_val, max_val, min, max, \
+ src, dst, src_pitch, dst_pitch, n); \
+ } \
+ static long \
+ convert_double_ ## name (void *src, \
+ void *dst, \
+ int src_pitch, \
+ int dst_pitch, \
+ long n) \
+ { \
+ return convert_double_u32_scaled (min_val, max_val, min, max, \
+ src, dst, src_pitch, dst_pitch, n); \
+ }
-MAKE_CONVERSIONS(u32,0.0,1.0,0,UINT32_MAX);
+MAKE_CONVERSIONS (u32, 0.0, 1.0, 0, UINT32_MAX);
void
babl_base_type_u32 (void)
{
babl_type_new (
"u32",
- "id", BABL_U32,
+ "id", BABL_U32,
"bits", 32,
NULL);
{
while (n--)
{
- double dval = *(double *) src;
+ double dval = *(double *) src;
unsigned char u8val;
if (dval < min_val)
else if (dval > max_val)
u8val = max;
else
- u8val = rint ((dval-min_val) / (max_val-min_val) * (max-min) + min);
+ u8val = rint ((dval - min_val) / (max_val - min_val) * (max - min) + min);
*(unsigned char *) dst = u8val;
- src += src_pitch;
- dst += dst_pitch;
+ src += src_pitch;
+ dst += dst_pitch;
}
return n;
}
else if (u8val > max)
dval = max_val;
else
- dval = (u8val-min) / (double)(max-min) * (max_val-min_val) + min_val;
+ dval = (u8val - min) / (double) (max - min) * (max_val - min_val) + min_val;
(*(double *) dst) = dval;
}
#define MAKE_CONVERSIONS(name, min_val, max_val, min, max) \
-static long \
-convert_##name##_double (void *src, \
- void *dst, \
- int src_pitch, \
- int dst_pitch, \
- long n) \
-{ \
- return convert_u8_double_scaled (min_val, max_val, min, max, \
- src, dst, src_pitch, dst_pitch, n); \
-} \
-static long \
-convert_double_##name (void *src, \
- void *dst, \
- int src_pitch, \
- int dst_pitch, \
- long n) \
-{ \
- return convert_double_u8_scaled (min_val, max_val, min, max, \
- src, dst, src_pitch, dst_pitch, n); \
-}
+ static long \
+ convert_ ## name ## _double (void *src, \
+ void *dst, \
+ int src_pitch, \
+ int dst_pitch, \
+ long n) \
+ { \
+ return convert_u8_double_scaled (min_val, max_val, min, max, \
+ src, dst, src_pitch, dst_pitch, n); \
+ } \
+ static long \
+ convert_double_ ## name (void *src, \
+ void *dst, \
+ int src_pitch, \
+ int dst_pitch, \
+ long n) \
+ { \
+ return convert_double_u8_scaled (min_val, max_val, min, max, \
+ src, dst, src_pitch, dst_pitch, n); \
+ }
-MAKE_CONVERSIONS (u8, 0.0, 1.0, 0x00, UINT8_MAX);
-MAKE_CONVERSIONS (u8_luma, 0.0, 1.0, 16, 235);
+MAKE_CONVERSIONS (u8, 0.0, 1.0, 0x00, UINT8_MAX);
+MAKE_CONVERSIONS (u8_luma, 0.0, 1.0, 16, 235);
MAKE_CONVERSIONS (u8_chroma, 0.0, 1.0, 16, 240);
void
{
babl_type_new (
"u8",
- "id", BABL_U8,
+ "id", BABL_U8,
"bits", 8,
NULL);
babl_type_new (
"u8-luma",
- "id", BABL_U8_LUMA,
- "bits", 8,
+ "id", BABL_U8_LUMA,
+ "bits", 8,
NULL
);
babl_type_new (
"u8-chroma",
- "id", BABL_U8_CHROMA,
+ "id", BABL_U8_CHROMA,
"integer",
"unsigned",
- "bits", 8,
- "min", (long) 16,
- "max", (long)240,
- "min_val", -0.5,
- "max_val", 0.5,
+ "bits", 8,
+ "min", (long) 16,
+ "max", (long) 240,
+ "min_val", -0.5,
+ "max_val", 0.5,
NULL
);
babl_conversion_new (
babl_type_id (BABL_U8),
babl_type_id (BABL_DOUBLE),
- "plane", convert_u8_double,
+ "plane", convert_u8_double,
NULL
);
babl_conversion_new (
babl_type_id (BABL_DOUBLE),
babl_type_id (BABL_U8),
- "plane", convert_double_u8,
+ "plane", convert_double_u8,
NULL
);
babl_conversion_new (
babl_type_id (BABL_U8_LUMA),
babl_type_id (BABL_DOUBLE),
- "plane", convert_u8_luma_double,
+ "plane", convert_u8_luma_double,
NULL
);
babl_conversion_new (
babl_type_id (BABL_DOUBLE),
babl_type_id (BABL_U8_LUMA),
- "plane", convert_double_u8_luma,
+ "plane", convert_double_u8_luma,
NULL
);
babl_conversion_new (
babl_type_id (BABL_U8_CHROMA),
babl_type_id (BABL_DOUBLE),
- "plane", convert_u8_chroma_double,
+ "plane", convert_u8_chroma_double,
NULL
);
babl_conversion_new (
babl_type_id (BABL_DOUBLE),
babl_type_id (BABL_U8_CHROMA),
- "plane", convert_double_u8_chroma,
+ "plane", convert_double_u8_chroma,
NULL
);
}
-/*\r
- * timeval.h 1.0 01/12/19\r
- *\r
- * Defines gettimeofday, timeval, etc. for Win32\r
- *\r
- * By Wu Yongwei\r
- *\r
- */\r
-\r
-#ifdef _WIN32\r
-\r
-#define WIN32_LEAN_AND_MEAN\r
-#include <windows.h>\r
-#include <time.h>\r
-\r
-#ifndef __GNUC__\r
-#define EPOCHFILETIME (116444736000000000i64)\r
-#else\r
-#define EPOCHFILETIME (116444736000000000LL)\r
-#endif\r
-\r
-struct timeval {\r
- long tv_sec; /* seconds */\r
- long tv_usec; /* microseconds */\r
-};\r
-\r
-struct timezone {\r
- int tz_minuteswest; /* minutes W of Greenwich */\r
- int tz_dsttime; /* type of dst correction */\r
-};\r
-\r
-\r
-int gettimeofday(struct timeval *tv, struct timezone *tz)\r
-{\r
- FILETIME ft;\r
- LARGE_INTEGER li;\r
- __int64 t;\r
- static int tzflag;\r
-\r
- if (tv)\r
- {\r
- GetSystemTimeAsFileTime(&ft);\r
- li.LowPart = ft.dwLowDateTime;\r
- li.HighPart = ft.dwHighDateTime;\r
- t = li.QuadPart; /* In 100-nanosecond intervals */\r
- t -= EPOCHFILETIME; /* Offset to the Epoch time */\r
- t /= 10; /* In microseconds */\r
- tv->tv_sec = (long)(t / 1000000);\r
- tv->tv_usec = (long)(t % 1000000);\r
- }\r
-\r
- if (tz)\r
- {\r
- if (!tzflag)\r
- {\r
- _tzset();\r
- tzflag++;\r
- }\r
- tz->tz_minuteswest = _timezone / 60;\r
- tz->tz_dsttime = _daylight;\r
- }\r
-\r
- return 0;\r
-}\r
-\r
-#endif /* _WIN32 */\r
+/*
+ * timeval.h 1.0 01/12/19
+ *
+ * Defines gettimeofday, timeval, etc. for Win32
+ *
+ * By Wu Yongwei
+ *
+ */
+
+#ifdef _WIN32
+
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+#include <time.h>
+
+#ifndef __GNUC__
+#define EPOCHFILETIME (116444736000000000i 64)
+#else
+#define EPOCHFILETIME (116444736000000000LL)
+#endif
+
+struct timeval
+{
+ long tv_sec; /* seconds */
+ long tv_usec; /* microseconds */
+};
+
+struct timezone
+{
+ int tz_minuteswest; /* minutes W of Greenwich */
+ int tz_dsttime; /* type of dst correction */
+};
+
+
+int gettimeofday (struct timeval *tv, struct timezone *tz)
+{
+ FILETIME ft;
+ LARGE_INTEGER li;
+ __int64 t;
+ static int tzflag;
+
+ if (tv)
+ {
+ GetSystemTimeAsFileTime (&ft);
+ li.LowPart = ft.dwLowDateTime;
+ li.HighPart = ft.dwHighDateTime;
+ t = li.QuadPart;/* In 100-nanosecond intervals */
+ t -= EPOCHFILETIME;/* Offset to the Epoch time */
+ t /= 10; /* In microseconds */
+ tv->tv_sec = (long) (t / 1000000);
+ tv->tv_usec = (long) (t % 1000000);
+ }
+
+ if (tz)
+ {
+ if (!tzflag)
+ {
+ _tzset ();
+ tzflag++;
+ }
+ tz->tz_minuteswest = _timezone / 60;
+ tz->tz_dsttime = _daylight;
+ }
+
+ return 0;
+}
+
+#endif /* _WIN32 */
int init (void);
-static void types (void);
-static void components (void);
-static void models (void);
-static void conversions (void);
-static void formats (void);
+static void types (void);
+static void components (void);
+static void models (void);
+static void conversions (void);
+static void formats (void);
int
init (void)
{
- types ();
- components ();
- models ();
- formats ();
- conversions ();
+ types ();
+ components ();
+ models ();
+ formats ();
+ conversions ();
return 0;
}
static void
components (void)
{
- babl_component_new ( "CIE L", NULL);
- babl_component_new ( "CIE a", "chroma", NULL);
- babl_component_new ( "CIE b", "chroma", NULL);
+ babl_component_new ("CIE L", NULL);
+ babl_component_new ("CIE a", "chroma", NULL);
+ babl_component_new ("CIE b", "chroma", NULL);
}
static void
NULL);
}
-/*********** cpercep.h ********* */
+/*********** cpercep.h ********* */
/*
-Copyright (C) 1997-2002 Adam D. Moss (the "Author"). All Rights Reserved.
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is fur-
-nished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FIT-
-NESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
-IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CON-
-NECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-Except as contained in this notice, the name of the Author of the
-Software shall not be used in advertising or otherwise to promote the sale,
-use or other dealings in this Software without prior written authorization
-from the Author.
-*/
+ Copyright (C) 1997-2002 Adam D. Moss (the "Author"). All Rights Reserved.
+
+ Permission is hereby granted, free of charge, to any person obtaining a copy
+ of this software and associated documentation files (the "Software"), to deal
+ in the Software without restriction, including without limitation the rights
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the Software is fur-
+ nished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included in
+ all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FIT-
+ NESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CON-
+ NECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+ Except as contained in this notice, the name of the Author of the
+ Software shall not be used in advertising or otherwise to promote the sale,
+ use or other dealings in this Software without prior written authorization
+ from the Author.
+ */
/*
- cpercep.c: The CPercep Functions v0.9: 2002-02-10
- Adam D. Moss: adam@gimp.org <http://www.foxbox.org/adam/code/cpercep/>
+ cpercep.c: The CPercep Functions v0.9: 2002-02-10
+ Adam D. Moss: adam@gimp.org <http://www.foxbox.org/adam/code/cpercep/>
- TODO: document functions, rename erroneously-named arguments
-*/
+ TODO: document functions, rename erroneously-named arguments
+ */
#ifndef __CPERCEP_H__
#define __CPERCEP_H__
-void cpercep_init (void);
+void cpercep_init (void);
void cpercep_rgb_to_space (double inr,
double ing,
/* This is in the header so that it can potentially be inlined. */
static const double
cpercep_distance_space (const double L1, const double a1, const double b1,
- const double L2, const double a2, const double b2)
+ const double L2, const double a2, const double b2)
{
const double Ld = L1 - L2;
const double ad = a1 - a2;
const double bd = b1 - b2;
- return (Ld*Ld + ad*ad + bd*bd);
+ return (Ld * Ld + ad * ad + bd * bd);
}
#endif
#endif /* __CPERCEP_H__ */
-/*********** /cpercep.h ********* */
+/*********** /cpercep.h ********* */
{
while (n--)
{
- double red = ((double*)src)[0];
- double green = ((double*)src)[1];
- double blue = ((double*)src)[2];
+ double red = ((double *) src)[0];
+ double green = ((double *) src)[1];
+ double blue = ((double *) src)[2];
double L, a, b;
cpercep_rgb_to_space (red, green, blue, &L, &a, &b);
- ((double*)dst)[0] = L;
- ((double*)dst)[1] = a;
- ((double*)dst)[2] = b;
+ ((double *) dst)[0] = L;
+ ((double *) dst)[1] = a;
+ ((double *) dst)[2] = b;
- src += sizeof(double) * 4;
- dst += sizeof(double) * 3;
+ src += sizeof (double) * 4;
+ dst += sizeof (double) * 3;
}
return n;
}
{
while (n--)
{
- double L = ((double*)src)[0];
- double a = ((double*)src)[1];
- double b = ((double*)src)[2];
+ double L = ((double *) src)[0];
+ double a = ((double *) src)[1];
+ double b = ((double *) src)[2];
double red, green, blue;
cpercep_space_to_rgb (L, a, b, &red, &green, &blue);
- ((double*)dst)[0] = red;
- ((double*)dst)[1] = green;
- ((double*)dst)[2] = blue;
- ((double*)dst)[3] = 1.0;
+ ((double *) dst)[0] = red;
+ ((double *) dst)[1] = green;
+ ((double *) dst)[2] = blue;
+ ((double *) dst)[3] = 1.0;
- src += sizeof(double) * 3;
- dst += sizeof(double) * 4;
+ src += sizeof (double) * 3;
+ dst += sizeof (double) * 4;
}
return n;
}
{
while (n--)
{
- double red = ((double*)src)[0];
- double green = ((double*)src)[1];
- double blue = ((double*)src)[2];
- double alpha = ((double*)src)[3];
+ double red = ((double *) src)[0];
+ double green = ((double *) src)[1];
+ double blue = ((double *) src)[2];
+ double alpha = ((double *) src)[3];
double L, a, b;
cpercep_rgb_to_space (red, green, blue, &L, &a, &b);
- ((double*)dst)[0] = L;
- ((double*)dst)[1] = a;
- ((double*)dst)[2] = b;
- ((double*)dst)[3] = alpha;
+ ((double *) dst)[0] = L;
+ ((double *) dst)[1] = a;
+ ((double *) dst)[2] = b;
+ ((double *) dst)[3] = alpha;
- src += sizeof(double) * 4;
- dst += sizeof(double) * 4;
+ src += sizeof (double) * 4;
+ dst += sizeof (double) * 4;
}
return n;
}
{
while (n--)
{
- double L = ((double*)src)[0];
- double a = ((double*)src)[1];
- double b = ((double*)src)[2];
- double alpha = ((double*)src)[3];
+ double L = ((double *) src)[0];
+ double a = ((double *) src)[1];
+ double b = ((double *) src)[2];
+ double alpha = ((double *) src)[3];
double red, green, blue;
cpercep_space_to_rgb (L, a, b, &red, &green, &blue);
- ((double*)dst)[0] = red;
- ((double*)dst)[1] = green;
- ((double*)dst)[2] = blue;
- ((double*)dst)[3] = alpha;
+ ((double *) dst)[0] = red;
+ ((double *) dst)[1] = green;
+ ((double *) dst)[2] = blue;
+ ((double *) dst)[3] = alpha;
- src += sizeof(double) * 4;
- dst += sizeof(double) * 4;
+ src += sizeof (double) * 4;
+ dst += sizeof (double) * 4;
}
return n;
}
static void
conversions (void)
{
-
babl_conversion_new (
babl_model ("RGBA"),
babl_model ("CIE Lab"),
- "linear", rgba_to_lab,
+ "linear", rgba_to_lab,
NULL
);
babl_conversion_new (
babl_model ("CIE Lab"),
babl_model ("RGBA"),
- "linear", lab_to_rgba,
+ "linear", lab_to_rgba,
NULL
);
babl_conversion_new (
babl_model ("RGBA"),
babl_model ("CIE Lab alpha"),
- "linear", rgba_to_laba,
+ "linear", rgba_to_laba,
NULL
);
babl_conversion_new (
babl_model ("CIE Lab alpha"),
babl_model ("RGBA"),
- "linear", laba_to_rgba,
+ "linear", laba_to_rgba,
NULL
);
- cpercep_init ();
+ cpercep_init ();
}
static void
formats (void)
{
babl_format_new (
- "name", "CIE Lab float",
- babl_model ("CIE Lab"),
+ "name", "CIE Lab float",
+ babl_model ("CIE Lab"),
- babl_type ("float"),
- babl_component ("CIE L"),
- babl_component ("CIE a"),
+ babl_type ("float"),
+ babl_component ("CIE L"),
+ babl_component ("CIE a"),
babl_component ("CIE b"),
NULL);
babl_format_new (
- "name", "CIE Lab alpha float",
- babl_model ("CIE Lab alpha"),
+ "name", "CIE Lab alpha float",
+ babl_model ("CIE Lab alpha"),
- babl_type ("double"),
- babl_component ("CIE L"),
- babl_component ("CIE a"),
+ babl_type ("double"),
+ babl_component ("CIE L"),
+ babl_component ("CIE a"),
babl_component ("CIE b"),
babl_component ("A"),
NULL);
babl_format_new (
- "name", "CIE Lab u8",
- babl_model ("CIE Lab"),
+ "name", "CIE Lab u8",
+ babl_model ("CIE Lab"),
- babl_type ("CIE u8 L"),
+ babl_type ("CIE u8 L"),
babl_component ("CIE L"),
- babl_type ("CIE u8 ab"),
- babl_component ("CIE a"),
- babl_type ("CIE u8 ab"),
+ babl_type ("CIE u8 ab"),
+ babl_component ("CIE a"),
+ babl_type ("CIE u8 ab"),
babl_component ("CIE b"),
NULL);
babl_format_new (
- "name", "CIE Lab u16",
- babl_model ("CIE Lab"),
+ "name", "CIE Lab u16",
+ babl_model ("CIE Lab"),
- babl_type ("CIE u16 L"),
+ babl_type ("CIE u16 L"),
babl_component ("CIE L"),
- babl_type ("CIE u16 ab"),
- babl_component ("CIE a"),
- babl_type ("CIE u16 ab"),
+ babl_type ("CIE u16 ab"),
+ babl_component ("CIE a"),
+ babl_type ("CIE u16 ab"),
babl_component ("CIE b"),
NULL);
}
{
while (n--)
{
- double dval = *(double *) src;
+ double dval = *(double *) src;
unsigned char u8val;
if (dval < min_val)
else if (dval > max_val)
u8val = max;
else
- u8val = rint ((dval-min_val) / (max_val-min_val) * (max-min) + min);
+ u8val = rint ((dval - min_val) / (max_val - min_val) * (max - min) + min);
*(unsigned char *) dst = u8val;
- src += src_pitch;
- dst += dst_pitch;
+ src += src_pitch;
+ dst += dst_pitch;
}
return n;
}
else if (u8val > max)
dval = max_val;
else
- dval = (u8val-min) / (double)(max-min) * (max_val-min_val) + min_val;
+ dval = (u8val - min) / (double) (max - min) * (max_val - min_val) + min_val;
(*(double *) dst) = dval;
}
#define MAKE_CONVERSIONS(name, min_val, max_val, min, max) \
-static long \
-convert_##name##_double (char *src, \
- char *dst, \
- int src_pitch, \
- int dst_pitch, \
- long n) \
-{ \
- return convert_u8_double_scaled (min_val, max_val, min, max, \
- src, dst, src_pitch, dst_pitch, n); \
-} \
-static long \
-convert_double_##name (char *src, \
- char *dst, \
- int src_pitch, \
- int dst_pitch, \
- long n) \
-{ \
- return convert_double_u8_scaled (min_val, max_val, min, max, \
- src, dst, src_pitch, dst_pitch, n); \
-}
+ static long \
+ convert_ ## name ## _double (char *src, \
+ char *dst, \
+ int src_pitch, \
+ int dst_pitch, \
+ long n) \
+ { \
+ return convert_u8_double_scaled (min_val, max_val, min, max, \
+ src, dst, src_pitch, dst_pitch, n); \
+ } \
+ static long \
+ convert_double_ ## name (char *src, \
+ char *dst, \
+ int src_pitch, \
+ int dst_pitch, \
+ long n) \
+ { \
+ return convert_double_u8_scaled (min_val, max_val, min, max, \
+ src, dst, src_pitch, dst_pitch, n); \
+ }
/* source ICC.1:2004-10 */
-MAKE_CONVERSIONS (u8_l, 0.0, 100.0, 0x00, 0xff);
+MAKE_CONVERSIONS (u8_l, 0.0, 100.0, 0x00, 0xff);
MAKE_CONVERSIONS (u8_ab, -128.0, 127.0, 0x00, 0xff);
#undef MAKE_CONVERSIONS
"CIE u8 L",
"integer",
"unsigned",
- "bits", 8,
- "min_val", 0.0,
- "max_val", 100.0,
+ "bits", 8,
+ "min_val", 0.0,
+ "max_val", 100.0,
NULL
);
"CIE u8 ab",
"integer",
"unsigned",
- "bits", 8,
- "min_val", -50.0,
- "max_val", 50.0,
+ "bits", 8,
+ "min_val", -50.0,
+ "max_val", 50.0,
NULL
);
babl_conversion_new (
babl_type ("CIE u8 L"),
babl_type ("double"),
- "plane", convert_u8_l_double,
+ "plane", convert_u8_l_double,
NULL
);
babl_conversion_new (
babl_type ("double"),
babl_type ("CIE u8 L"),
- "plane", convert_double_u8_l,
+ "plane", convert_double_u8_l,
NULL
);
babl_conversion_new (
babl_type ("CIE u8 ab"),
babl_type ("double"),
- "plane", convert_u8_ab_double,
+ "plane", convert_u8_ab_double,
NULL
);
babl_conversion_new (
babl_type ("double"),
babl_type ("CIE u8 ab"),
- "plane", convert_double_u8_ab,
+ "plane", convert_double_u8_ab,
NULL
);
}
else if (dval > max_val)
u16val = max;
else
- u16val = rint ((dval-min_val) / (max_val-min_val) * (max-min) + min);
+ u16val = rint ((dval - min_val) / (max_val - min_val) * (max - min) + min);
*(unsigned short *) dst = u16val;
- dst += dst_pitch;
- src += src_pitch;
+ dst += dst_pitch;
+ src += src_pitch;
}
return n;
}
{
while (n--)
{
- int u16val = *(unsigned short*) src;
+ int u16val = *(unsigned short *) src;
double dval;
if (u16val < min)
else if (u16val > max)
dval = max_val;
else
- dval = (u16val-min) / (double)(max-min) * (max_val-min_val) + min_val;
+ dval = (u16val - min) / (double) (max - min) * (max_val - min_val) + min_val;
(*(double *) dst) = dval;
- dst += dst_pitch;
- src += src_pitch;
+ dst += dst_pitch;
+ src += src_pitch;
}
return n;
}
#define MAKE_CONVERSIONS(name, min_val, max_val, min, max) \
-static long \
-convert_##name##_double (char *src, \
- char *dst, \
- int src_pitch, \
- int dst_pitch, \
- long n) \
-{ \
- return convert_u16_double_scaled (min_val, max_val, min, max, \
- src, dst, src_pitch, dst_pitch, n);\
-} \
-static long \
-convert_double_##name (char *src, \
- char *dst, \
- int src_pitch, \
- int dst_pitch, \
- long n) \
-{ \
- return convert_double_u16_scaled (min_val, max_val, min, max, \
- src, dst, src_pitch, dst_pitch, n);\
-}
+ static long \
+ convert_ ## name ## _double (char *src, \
+ char *dst, \
+ int src_pitch, \
+ int dst_pitch, \
+ long n) \
+ { \
+ return convert_u16_double_scaled (min_val, max_val, min, max, \
+ src, dst, src_pitch, dst_pitch, n); \
+ } \
+ static long \
+ convert_double_ ## name (char *src, \
+ char *dst, \
+ int src_pitch, \
+ int dst_pitch, \
+ long n) \
+ { \
+ return convert_double_u16_scaled (min_val, max_val, min, max, \
+ src, dst, src_pitch, dst_pitch, n); \
+ }
-MAKE_CONVERSIONS (u16_l, 0.0, 100.0, 0x00, 0xffff);
+MAKE_CONVERSIONS (u16_l, 0.0, 100.0, 0x00, 0xffff);
MAKE_CONVERSIONS (u16_ab, -128.0, 127.0, 0x00, 0xffff);
#undef MAKE_CONVERSIONS
static void
types_u16 (void)
{
-
babl_type_new (
"CIE u16 L",
"integer",
"unsigned",
- "bits", 16,
- "min_val", 0.0,
- "max_val", 100.0,
+ "bits", 16,
+ "min_val", 0.0,
+ "max_val", 100.0,
NULL
);
babl_type_new (
"CIE u16 ab",
- "id", "CIE u8 ab",
+ "id", "CIE u8 ab",
"integer",
"unsigned",
- "bits", 16,
- "min_val", -50.0,
- "max_val", 50.0,
+ "bits", 16,
+ "min_val", -50.0,
+ "max_val", 50.0,
NULL
);
babl_conversion_new (
babl_type ("CIE u16 L"),
babl_type ("double"),
- "plane", convert_u16_l_double,
+ "plane", convert_u16_l_double,
NULL
);
babl_conversion_new (
babl_type ("double"),
babl_type ("CIE u16 L"),
- "plane", convert_double_u16_l,
+ "plane", convert_double_u16_l,
NULL
);
babl_conversion_new (
babl_type ("CIE u16 ab"),
babl_type ("double"),
- "plane", convert_u16_ab_double,
+ "plane", convert_u16_ab_double,
NULL
);
babl_conversion_new (
babl_type ("double"),
babl_type ("CIE u16 ab"),
- "plane", convert_double_u16_ab,
+ "plane", convert_double_u16_ab,
NULL
);
}
-/*********** cpercep.c ********* */
+/*********** cpercep.c ********* */
/*
-Copyright (C) 1999-2002 Adam D. Moss (the "Author"). All Rights Reserved.
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is fur-
-nished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FIT-
-NESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
-IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CON-
-NECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-Except as contained in this notice, the name of the Author of the
-Software shall not be used in advertising or otherwise to promote the sale,
-use or other dealings in this Software without prior written authorization
-from the Author.
-*/
+ Copyright (C) 1999-2002 Adam D. Moss (the "Author"). All Rights Reserved.
+
+ Permission is hereby granted, free of charge, to any person obtaining a copy
+ of this software and associated documentation files (the "Software"), to deal
+ in the Software without restriction, including without limitation the rights
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the Software is fur-
+ nished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included in
+ all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FIT-
+ NESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CON-
+ NECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+ Except as contained in this notice, the name of the Author of the
+ Software shall not be used in advertising or otherwise to promote the sale,
+ use or other dealings in this Software without prior written authorization
+ from the Author.
+ */
/*
- cpercep.c: The CPercep Functions v0.9: 2002-02-10
- Adam D. Moss: adam@gimp.org <http://www.foxbox.org/adam/code/cpercep/>
-
- This code module concerns itself with conversion from a hard-coded
- RGB colour space (sRGB by default) to CIE L*a*b* and back again with
- (primarily) precision and (secondarily) speed, oriented largely
- towards the purposes of quantifying the PERCEPTUAL difference between
- two arbitrary RGB colours with a minimum of fuss.
-
- Motivation One: The author is disheartened at the amount of graphics
- processing software around which uses weighted or non-weighted
- Euclidean distance between co-ordinates within a (poorly-defined) RGB
- space as the basis of what should really be an estimate of perceptual
- difference to the human eye. Certainly it's fast to do it that way,
- but please think carefully about whether your particular application
- should be tolerating sloppy results for the sake of real-time response.
-
- Motivation Two: Lack of tested, re-usable and free code available
- for this purpose. The difficulty in finding something similar to
- CPercep with a free license motivated this project; I hope that this
- code also serves to illustrate how to perform the
- R'G'B'->XYZ->L*a*b*->XYZ->R'G'B' transformation correctly since I
- was distressed to note how many of the equations and code snippets
- on the net were omitting the reverse transform and/or were using
- incorrectly-derived or just plain wrong constants.
-
- TODO: document functions, rename erroneously-named arguments
-*/
+ cpercep.c: The CPercep Functions v0.9: 2002-02-10
+ Adam D. Moss: adam@gimp.org <http://www.foxbox.org/adam/code/cpercep/>
+
+ This code module concerns itself with conversion from a hard-coded
+ RGB colour space (sRGB by default) to CIE L*a*b* and back again with
+ (primarily) precision and (secondarily) speed, oriented largely
+ towards the purposes of quantifying the PERCEPTUAL difference between
+ two arbitrary RGB colours with a minimum of fuss.
+
+ Motivation One: The author is disheartened at the amount of graphics
+ processing software around which uses weighted or non-weighted
+ Euclidean distance between co-ordinates within a (poorly-defined) RGB
+ space as the basis of what should really be an estimate of perceptual
+ difference to the human eye. Certainly it's fast to do it that way,
+ but please think carefully about whether your particular application
+ should be tolerating sloppy results for the sake of real-time response.
+
+ Motivation Two: Lack of tested, re-usable and free code available
+ for this purpose. The difficulty in finding something similar to
+ CPercep with a free license motivated this project; I hope that this
+ code also serves to illustrate how to perform the
+ R'G'B'->XYZ->L*a*b*->XYZ->R'G'B' transformation correctly since I
+ was distressed to note how many of the equations and code snippets
+ on the net were omitting the reverse transform and/or were using
+ incorrectly-derived or just plain wrong constants.
+
+ TODO: document functions, rename erroneously-named arguments
+ */
/* defines added to make it compile outside gimp */
#ifndef gboolean
-#define gboolean int
+#define gboolean int
#endif
#ifndef FALSE
-#define FALSE 0
+#define FALSE 0
#endif
#ifndef TRUE
-#define TRUE 1
+#define TRUE 1
#endif
#ifndef __GLIBC__
/* cbrt() is a GNU extension */
-#define cbrt(x) (pow(x, 1.0/3.0))
+#define cbrt(x) (pow (x, 1.0 / 3.0))
#endif
/* #include "cpercep.h" */
destined for an sRGB-alike display device (a typical modern monitor)
-- if you change this then you'll probably want to change ASSUMED_GAMMA,
the phosphor colours and the white point definition.
-*/
+ */
/* #define SANITY */
/* #define APPROX */
#ifdef SRGB
-#define ASSUMED_GAMMA (2.2F)
+#define ASSUMED_GAMMA (2.2F)
#else
/*#define ASSUMED_GAMMA (2.591F)*/
-#define ASSUMED_GAMMA (1.0F)
+#define ASSUMED_GAMMA (1.0F)
#endif
-#define REV_GAMMA ((1.0F / ASSUMED_GAMMA))
+#define REV_GAMMA ((1.0F / ASSUMED_GAMMA))
/* define characteristics of the source RGB space (and the space
#ifndef CLAMP
-#define CLAMP(x,l,u) ((x)<(l)?(l):((x)>(u)?(u):(x)))
+#define CLAMP(x, l, u) ((x) < (l) ? (l) : ((x) > (u) ? (u) : (x)))
#endif
static void
-init_powtable(const double gamma)
+init_powtable (const double gamma)
{
int i;
#ifndef SRGB
/* pure gamma function */
- for (i=0; i<256; i++)
+ for (i = 0; i < 256; i++)
{
- powtable[i] = pow((i)/255.0F, gamma);
+ powtable[i] = pow ((i) / 255.0F, gamma);
}
#else
/* sRGB gamma curve */
- for (i=0; i<11 /* 0.03928 * 255 */; i++)
+ for (i = 0; i < 11 /* 0.03928 * 255 */; i++)
{
powtable[i] = (i) / (255.0F * 12.92F);
}
- for (; i<256; i++)
+ for (; i < 256; i++)
{
- powtable[i] = pow( (((i) / 255.0F) + 0.055F) / 1.055F, 2.4F);
+ powtable[i] = pow ((((i) / 255.0F) + 0.055F) / 1.055F, 2.4F);
}
#endif
}
static void
-rgbxyzrgb_init(void)
+rgbxyzrgb_init (void)
{
init_powtable (ASSUMED_GAMMA);
{
CMatrix MRC, MRCi;
- double C1,C2,C3;
+ double C1, C2, C3;
MRC[0][0] = pxr;
MRC[0][1] = pxg;
Minvert (MRC, MRCi);
- C1 = MRCi[0][0]*xnn + MRCi[0][1] + MRCi[0][2]*znn;
- C2 = MRCi[1][0]*xnn + MRCi[1][1] + MRCi[1][2]*znn;
- C3 = MRCi[2][0]*xnn + MRCi[2][1] + MRCi[2][2]*znn;
+ C1 = MRCi[0][0] * xnn + MRCi[0][1] + MRCi[0][2] * znn;
+ C2 = MRCi[1][0] * xnn + MRCi[1][1] + MRCi[1][2] * znn;
+ C3 = MRCi[2][0] * xnn + MRCi[2][1] + MRCi[2][2] * znn;
Mrgb_to_xyz[0][0] = MRC[0][0] * C1;
Mrgb_to_xyz[0][1] = MRC[0][1] * C2;
static void
xyz_to_rgb (double *inx_outr,
- double *iny_outg,
- double *inz_outb)
+ double *iny_outg,
+ double *inz_outb)
{
const double x = *inx_outr;
const double y = *iny_outg;
const double z = *inz_outb;
- *inx_outr = Mxyz_to_rgb[0][0]*x + Mxyz_to_rgb[0][1]*y + Mxyz_to_rgb[0][2]*z;
- *iny_outg = Mxyz_to_rgb[1][0]*x + Mxyz_to_rgb[1][1]*y + Mxyz_to_rgb[1][2]*z;
- *inz_outb = Mxyz_to_rgb[2][0]*x + Mxyz_to_rgb[2][1]*y + Mxyz_to_rgb[2][2]*z;
+ *inx_outr = Mxyz_to_rgb[0][0] * x + Mxyz_to_rgb[0][1] * y + Mxyz_to_rgb[0][2] * z;
+ *iny_outg = Mxyz_to_rgb[1][0] * x + Mxyz_to_rgb[1][1] * y + Mxyz_to_rgb[1][2] * z;
+ *inz_outb = Mxyz_to_rgb[2][0] * x + Mxyz_to_rgb[2][1] * y + Mxyz_to_rgb[2][2] * z;
}
static void
rgb_to_xyz (double *inr_outx,
- double *ing_outy,
- double *inb_outz)
+ double *ing_outy,
+ double *inb_outz)
{
const double r = *inr_outx;
const double g = *ing_outy;
const double b = *inb_outz;
- *inr_outx = Mrgb_to_xyz[0][0]*r + Mrgb_to_xyz[0][1]*g + Mrgb_to_xyz[0][2]*b;
- *ing_outy = Mrgb_to_xyz[1][0]*r + Mrgb_to_xyz[1][1]*g + Mrgb_to_xyz[1][2]*b;
- *inb_outz = Mrgb_to_xyz[2][0]*r + Mrgb_to_xyz[2][1]*g + Mrgb_to_xyz[2][2]*b;
+ *inr_outx = Mrgb_to_xyz[0][0] * r + Mrgb_to_xyz[0][1] * g + Mrgb_to_xyz[0][2] * b;
+ *ing_outy = Mrgb_to_xyz[1][0] * r + Mrgb_to_xyz[1][1] * g + Mrgb_to_xyz[1][2] * b;
+ *inb_outz = Mrgb_to_xyz[2][0] * r + Mrgb_to_xyz[2][1] * g + Mrgb_to_xyz[2][2] * b;
}
static inline double
-ffunc(const double t)
+ffunc (const double t)
{
if (t > 0.008856F)
{
- return (cbrt(t));
+ return (cbrt (t));
}
else
{
- return (7.787F * t + 16.0F/116.0F);
+ return (7.787F * t + 16.0F / 116.0F);
}
}
static inline double
-ffunc_inv(const double t)
+ffunc_inv (const double t)
{
if (t > 0.206893F)
{
}
else
{
- return ((t - 16.0F/116.0F) / 7.787F);
+ return ((t - 16.0F / 116.0F) / 7.787F);
}
}
static void
xyz_to_lab (double *inx,
- double *iny,
- double *inz)
+ double *iny,
+ double *inz)
{
- double L,a,b;
- double ffuncY;
+ double L, a, b;
+ double ffuncY;
const double X = *inx;
const double Y = *iny;
const double Z = *inz;
if (Y > 0.0F)
{
if (Y > 0.008856F)
- {
- L = (116.0F * cbrt(Y)) - 16.0F;
- }
+ {
+ L = (116.0F * cbrt (Y)) - 16.0F;
+ }
else
- {
- L = (Y * 903.3F);
- }
+ {
+ L = (Y * 903.3F);
+ }
#ifdef SANITY
if (L < 0.0F)
- {
- g_printerr (" <eek1>%f \007",(float)L);
- }
+ {
+ g_printerr (" <eek1>%f \007", (float) L);
+ }
if (L > 100.0F)
- {
- g_printerr (" <eek2>%f \007",(float)L);
- }
+ {
+ g_printerr (" <eek2>%f \007", (float) L);
+ }
#endif
}
else
L = 0.0;
}
- ffuncY = ffunc(Y);
- a = 500.0F * (ffunc(X/xnn) - ffuncY);
- b = 200.0F * (ffuncY - ffunc(Z/znn));
+ ffuncY = ffunc (Y);
+ a = 500.0F * (ffunc (X / xnn) - ffuncY);
+ b = 200.0F * (ffuncY - ffunc (Z / znn));
*inx = L;
*iny = a;
static void
lab_to_xyz (double *inl,
- double *ina,
- double *inb)
+ double *ina,
+ double *inb)
{
- double X,Y,Z;
- double P;
+ double X, Y, Z;
+ double P;
const double L = *inl;
const double a = *ina;
const double b = *inb;
else
{
Y = L / 903.3F;
- P = 7.787F * Y + 16.0F/116.0F;
+ P = 7.787F * Y + 16.0F / 116.0F;
}
X = (P + a / 500.0F);
- X = xnn * ffunc_inv(X);
+ X = xnn *ffunc_inv (X);
Z = (P - b / 200.0F);
- Z = znn * ffunc_inv(Z);
+ Z = znn *ffunc_inv (Z);
#ifdef SANITY
- if (X<-0.00000F)
+ if (X < -0.00000F)
{
- if (X<-0.0001F)
- g_printerr ("{badX %f {%f,%f,%f}}",X,L,a,b);
+ if (X < -0.0001F)
+ g_printerr ("{badX %f {%f,%f,%f}}", X, L, a, b);
X = 0.0F;
}
- if (Y<-0.00000F)
+ if (Y < -0.00000F)
{
- if (Y<-0.0001F)
- g_printerr ("{badY %f}",Y);
+ if (Y < -0.0001F)
+ g_printerr ("{badY %f}", Y);
Y = 0.0F;
}
- if (Z<-0.00000F)
+ if (Z < -0.00000F)
{
- if (Z<-0.1F)
- g_printerr ("{badZ %f}",Z);
+ if (Z < -0.1F)
+ g_printerr ("{badZ %f}", Z);
Z = 0.0F;
}
#endif
{
static gboolean initialized = FALSE;
- if (! initialized)
+ if (!initialized)
{
- rgbxyzrgb_init();
+ rgbxyzrgb_init ();
initialized = TRUE;
}
}
cpercep_rgb_to_space (double inr,
double ing,
double inb,
- double *outr,
+ double *outr,
double *outg,
double *outb)
{
(inr) < -0.0F ||
(ing) < -0.0F ||
(inb) < -0.0F
- )
- abort();
+ )
+ abort ();
#endif /* SANITY */
- inr = powtable[(int)inr];
- ing = powtable[(int)ing];
- inb = powtable[(int)inb];
+ inr = powtable[(int) inr];
+ ing = powtable[(int) ing];
+ inb = powtable[(int) inb];
#else
#ifdef SRGB
/* sRGB gamma curve */
if (inr <= (0.03928F * 255.0F))
- inr = inr / (255.0F * 12.92F);
+ inr = inr / (255.0F * 12.92F);
else
- inr = pow( (inr + (0.055F * 255.0F)) / (1.055F * 255.0F), 2.4F);
+ inr = pow ((inr + (0.055F * 255.0F)) / (1.055F * 255.0F), 2.4F);
if (ing <= (0.03928F * 255.0F))
- ing = ing / (255.0F * 12.92F);
+ ing = ing / (255.0F * 12.92F);
else
- ing = pow( (ing + (0.055F * 255.0F)) / (1.055F * 255.0F), 2.4F);
+ ing = pow ((ing + (0.055F * 255.0F)) / (1.055F * 255.0F), 2.4F);
if (inb <= (0.03928F * 255.0F))
- inb = inb / (255.0F * 12.92F);
+ inb = inb / (255.0F * 12.92F);
else
- inb = pow( (inb + (0.055F * 255.0F)) / (1.055F * 255.0F), 2.4F);
+ inb = pow ((inb + (0.055F * 255.0F)) / (1.055F * 255.0F), 2.4F);
#else
/* pure gamma function */
/* babl uses normalized RGB
- inr = pow((inr)/255.0F, ASSUMED_GAMMA);
- ing = pow((ing)/255.0F, ASSUMED_GAMMA);
- inb = pow((inb)/255.0F, ASSUMED_GAMMA);
- */
+ inr = pow((inr)/255.0F, ASSUMED_GAMMA);
+ ing = pow((ing)/255.0F, ASSUMED_GAMMA);
+ inb = pow((inb)/255.0F, ASSUMED_GAMMA);
+ */
#endif /* SRGB */
#endif /* APPROX */
(inr) < 0.0F ||
(ing) < 0.0F ||
(inb) < 0.0F
- )
+ )
{
g_printerr ("%%");
/* abort(); */
}
#endif /* SANITY */
- rgb_to_xyz(&inr, &ing, &inb);
+ rgb_to_xyz (&inr, &ing, &inb);
#ifdef SANITY
if (inr < 0.0F || ing < 0.0F || inb < 0.0F)
{
g_printerr (" [BAD2 XYZ: %f,%f,%f]\007 ",
- inr,ing,inb);
+ inr, ing, inb);
}
#endif /* SANITY */
- xyz_to_lab(&inr, &ing, &inb);
+ xyz_to_lab (&inr, &ing, &inb);
*outr = inr;
*outg = ing;
cpercep_space_to_rgb (double inr,
double ing,
double inb,
- double *outr,
+ double *outr,
double *outg,
double *outb)
{
- lab_to_xyz(&inr, &ing, &inb);
+ lab_to_xyz (&inr, &ing, &inb);
#ifdef SANITY
- if (inr<-0.0F || ing<-0.0F || inb<-0.0F)
+ if (inr < -0.0F || ing < -0.0F || inb < -0.0F)
{
g_printerr (" [BAD1 XYZ: %f,%f,%f]\007 ",
- inr,ing,inb);
+ inr, ing, inb);
}
#endif
- xyz_to_rgb(&inr, &ing, &inb);
+ xyz_to_rgb (&inr, &ing, &inb);
/* yes, essential. :( */
- inr = CLAMP(inr,0.0F,1.0F);
- ing = CLAMP(ing,0.0F,1.0F);
- inb = CLAMP(inb,0.0F,1.0F);
+ inr = CLAMP (inr, 0.0F, 1.0F);
+ ing = CLAMP (ing, 0.0F, 1.0F);
+ inb = CLAMP (inb, 0.0F, 1.0F);
#ifdef SRGB
if (inr <= 0.0030402477F)
inr = inr * (12.92F * 255.0F);
else
- inr = pow(inr, 1.0F/2.4F) * (1.055F * 255.0F) - (0.055F * 255.0F);
+ inr = pow (inr, 1.0F / 2.4F) * (1.055F * 255.0F) - (0.055F * 255.0F);
if (ing <= 0.0030402477F)
ing = ing * (12.92F * 255.0F);
else
- ing = pow(ing, 1.0F/2.4F) * (1.055F * 255.0F) - (0.055F * 255.0F);
+ ing = pow (ing, 1.0F / 2.4F) * (1.055F * 255.0F) - (0.055F * 255.0F);
if (inb <= 0.0030402477F)
inb = inb * (12.92F * 255.0F);
else
- inb = pow(inb, 1.0F/2.4F) * (1.055F * 255.0F) - (0.055F * 255.0F);
+ inb = pow (inb, 1.0F / 2.4F) * (1.055F * 255.0F) - (0.055F * 255.0F);
#else
/* babl uses normalized RGB values
- inr = 255.0F * pow(inr, REV_GAMMA);
- ing = 255.0F * pow(ing, REV_GAMMA);
- inb = 255.0F * pow(inb, REV_GAMMA);
- */
+ inr = 255.0F * pow(inr, REV_GAMMA);
+ ing = 255.0F * pow(ing, REV_GAMMA);
+ inb = 255.0F * pow(inb, REV_GAMMA);
+ */
#endif
*outr = inr;
/* EXPERIMENTAL SECTION */
const double
-xscaler(const double start, const double end,
- const double me, const double him)
+xscaler (const double start, const double end,
+ const double me, const double him)
{
- return start + ((end-start) * him) / (me + him);
+ return start + ((end - start) * him) / (me + him);
}
void
mix_colours (const double L1, const double a1, const double b1,
- const double L2, const double a2, const double b2,
- double *rtnL, double *rtna, double *rtnb,
- double mass1, double mass2)
+ const double L2, const double a2, const double b2,
+ double *rtnL, double *rtna, double *rtnb,
+ double mass1, double mass2)
{
double w1, w2;
*rtna = xscaler (a1, a2, mass1, mass2);
*rtnb = xscaler (b1, b2, mass1, mass2);
#else
-
#if 1
w1 = mass1 * L1;
w2 = mass2 * L2;
#else
- w1 = mass1 * (L1*L1*L1);
- w2 = mass2 * (L2*L2*L2);
+ w1 = mass1 * (L1 * L1 * L1);
+ w2 = mass2 * (L2 * L2 * L2);
#endif
*rtnL = xscaler (L1, L2, mass1, mass2);
if (w1 <= 0.0 &&
w2 <= 0.0)
{
- *rtna =
- *rtnb = 0.0;
+ *rtna =
+ *rtnb = 0.0;
#ifdef SANITY
/* g_printerr ("\007OUCH. "); */
#endif
}
else
{
- *rtna = xscaler(a1, a2, w1, w2);
- *rtnb = xscaler(b1, b2, w1, w2);
+ *rtna = xscaler (a1, a2, w1, w2);
+ *rtnb = xscaler (b1, b2, w1, w2);
}
#endif
}
#endif /* EXPERIMENTAL SECTION */
-/*********** /cpercep.c ********* */
+/*********** /cpercep.c ********* */
#include "babl.h"
-#define INLINE inline
+#define INLINE inline
#include <math.h>
#include <stdio.h>
*
* due to ability to be able to relicence gggl under a different
* licence than GPL, I avoided the temptation to look at the
- * source files in the same location, in case I was going to
+ * source files in the same location, in case I was going to
* need this piece of code for projects where GPL compatibility
* was a must.
*
linear_to_gamma_2_2 (double value)
{
if (value > 0.0030402477F)
- return 1.055F * pow (value, (1.0F/2.4F)) - 0.055F;
+ return 1.055F *pow (value, (1.0F / 2.4F)) - 0.055F;
return 12.92F * value;
}
#else
- #define linear_to_gamma_2_2(value) (pow((value), (1.0F/2.2F)))
- #define gamma_2_2_to_linear(value) (pow((value), 2.2F))
+ #define linear_to_gamma_2_2(value) (pow ((value), (1.0F / 2.2F)))
+ #define gamma_2_2_to_linear(value) (pow ((value), 2.2F))
#endif
/* lookup tables used in conversion */
-static float table_8_F[1 << 8];
-static float table_8g_F[1 << 8];
+static float table_8_F[1 << 8];
+static float table_8g_F[1 << 8];
static unsigned char table_F_8[1 << 16];
static unsigned char table_F_8g[1 << 16];
-static int table_inited = 0;
+static int table_inited = 0;
static void
table_init (void)
/* fill tables for conversion from integer to float */
{
- int i;
+ int i;
for (i = 0; i < 1 << 8; i++)
{
- float direct = i/255.0;
- table_8_F[i] = direct;
- table_8g_F[i] = gamma_2_2_to_linear(direct);
+ float direct = i / 255.0;
+ table_8_F[i] = direct;
+ table_8g_F[i] = gamma_2_2_to_linear (direct);
}
}
/* fill tables for conversion from float to integer */
{
union
{
- float f;
+ float f;
unsigned short s[2];
} u;
u.f = 0.0;
if (u.f <= 0.0)
{
- c = 0;
+ c = 0;
cg = 0;
}
else if (u.f >= 1.0)
{
- c = 255;
+ c = 255;
cg = 255;
}
else
{
c = rint (u.f * 255.0);
- cg = rint (linear_to_gamma_2_2(u.f) * 255.0);
+ cg = rint (linear_to_gamma_2_2 (u.f) * 255.0);
}
- table_F_8[u.s[1]] = c;
+ table_F_8[u.s[1]] = c;
table_F_8g[u.s[1]] = cg;
}
}
/* fix tables to ensure 1:1 conversions back and forth */
if (0)
{
- int i;
+ int i;
for (i = 0; i < 256; i++)
{
- float f = table_8_F[i];
- unsigned short *hi = ((unsigned short *)(void*) &f);
- unsigned short *lo = ((unsigned short *)(void*) &f);
- *lo = 0;
+ float f = table_8_F[i];
+ unsigned short *hi = ((unsigned short *) (void *) &f);
+ unsigned short *lo = ((unsigned short *) (void *) &f);
+ *lo = 0;
table_F_8[(*hi)] = i;
}
}
{
union
{
- float f;
+ float f;
unsigned short s[2];
} u;
u.f = f;
static INLINE long
conv_F_8 (unsigned char *src, unsigned char *dst, long samples)
{
- long n=samples;
+ long n = samples;
+
if (!table_inited)
table_init ();
while (n--)
{
register float f = (*(float *) src);
*(unsigned char *) dst = table_F_8[gggl_float_to_index16 (f)];
- dst += 1;
- src += 4;
+ dst += 1;
+ src += 4;
}
return samples;
}
static INLINE long
conv_F_8g (unsigned char *src, unsigned char *dst, long samples)
{
- long n=samples;
+ long n = samples;
+
if (!table_inited)
table_init ();
while (n--)
{
register float f = (*(float *) src);
*(unsigned char *) dst = table_F_8g[gggl_float_to_index16 (f)];
- dst += 1;
- src += 4;
+ dst += 1;
+ src += 4;
}
return samples;
}
static INLINE long
conv_8_F (unsigned char *src, unsigned char *dst, long samples)
{
- long n=samples;
+ long n = samples;
+
if (!table_inited)
table_init ();
while (n--)
{
(*(float *) dst) = table_8_F[*(unsigned char *) src];
- dst += 4;
- src += 1;
+ dst += 4;
+ src += 1;
}
return samples;
}
static INLINE long
conv_rgbaF_rgb8 (unsigned char *src, unsigned char *dst, long samples)
{
- long n=samples;
+ long n = samples;
+
while (n--)
- {
+ {
register float f = (*(float *) src);
*(unsigned char *) dst = table_F_8g[gggl_float_to_index16 (f)];
- src += 4;
- dst += 1;
+ src += 4;
+ dst += 1;
- f = (*(float *) src);
+ f = (*(float *) src);
*(unsigned char *) dst = table_F_8g[gggl_float_to_index16 (f)];
- src += 4;
- dst += 1;
+ src += 4;
+ dst += 1;
- f = (*(float *) src);
+ f = (*(float *) src);
*(unsigned char *) dst = table_F_8g[gggl_float_to_index16 (f)];
- src += 4;
- dst += 1;
+ src += 4;
+ dst += 1;
src += 4;
-
- }
+ }
return samples;
}
static INLINE long
conv_rgbaF_rgba8 (unsigned char *src, unsigned char *dst, long samples)
{
- long n=samples;
+ long n = samples;
+
while (n--)
- {
+ {
register float f = (*(float *) src);
*(unsigned char *) dst = table_F_8g[gggl_float_to_index16 (f)];
- src += 4;
- dst += 1;
+ src += 4;
+ dst += 1;
- f = (*(float *) src);
+ f = (*(float *) src);
*(unsigned char *) dst = table_F_8g[gggl_float_to_index16 (f)];
- src += 4;
- dst += 1;
+ src += 4;
+ dst += 1;
- f = (*(float *) src);
+ f = (*(float *) src);
*(unsigned char *) dst = table_F_8g[gggl_float_to_index16 (f)];
- src += 4;
- dst += 1;
+ src += 4;
+ dst += 1;
- f = (*(float *) src);
+ f = (*(float *) src);
*(unsigned char *) dst = table_F_8[gggl_float_to_index16 (f)];
- src += 4;
- dst += 1;
- }
+ src += 4;
+ dst += 1;
+ }
return samples;
}
-#define conv_rgbaF_rgbP8 conv_rgbaF_rgba8
+#define conv_rgbaF_rgbP8 conv_rgbaF_rgba8
static INLINE long
conv_rgbF_rgb8 (unsigned char *src, unsigned char *dst, long samples)
return samples;
}
-#define conv_rgbAF_rgbA8 conv_rgbaF_rgba8
-#define conv_gF_g8 conv_F_8
-#define conv_gAF_gA8 conv_gaF_ga8
+#define conv_rgbAF_rgbA8 conv_rgbaF_rgba8
+#define conv_gF_g8 conv_F_8
+#define conv_gAF_gA8 conv_gaF_ga8
static INLINE long
conv_rgba8_rgbaF (unsigned char *src, unsigned char *dst, long samples)
{
- long n=samples;
+ long n = samples;
+
while (n--)
{
(*(float *) dst) = table_8g_F[*(unsigned char *) src];
- dst += 4;
- src += 1;
+ dst += 4;
+ src += 1;
(*(float *) dst) = table_8g_F[*(unsigned char *) src];
- dst += 4;
- src += 1;
+ dst += 4;
+ src += 1;
(*(float *) dst) = table_8g_F[*(unsigned char *) src];
- dst += 4;
- src += 1;
+ dst += 4;
+ src += 1;
- (*(float *) dst) = table_8_F[*(unsigned char*) src];
- dst += 4;
- src += 1;
+ (*(float *) dst) = table_8_F[*(unsigned char *) src];
+ dst += 4;
+ src += 1;
}
return samples;
}
static INLINE long
conv_rgb8_rgbaF (unsigned char *src, unsigned char *dst, long samples)
{
- long n=samples;
+ long n = samples;
+
while (n--)
{
(*(float *) dst) = table_8g_F[*(unsigned char *) src];
- dst += 4;
- src += 1;
+ dst += 4;
+ src += 1;
(*(float *) dst) = table_8g_F[*(unsigned char *) src];
- dst += 4;
- src += 1;
+ dst += 4;
+ src += 1;
(*(float *) dst) = table_8g_F[*(unsigned char *) src];
- dst += 4;
- src += 1;
+ dst += 4;
+ src += 1;
(*(float *) dst) = 1.0;
- dst += 4;
+ dst += 4;
}
return samples;
}
unsigned char *dstc,
long samples)
{
- float *src = (void*)srcc;
- unsigned char *dst = (void*)dstc;
- long n=samples;
+ float *src = (void *) srcc;
+ unsigned char *dst = (void *) dstc;
+ long n = samples;
+
while (n--)
{
- int i;
+ int i;
float alpha = src[3];
if (alpha < 0.0001)
alpha = 0.0001;
- for (i=0;i<3;i++)
+ for (i = 0; i < 3; i++)
{
- float ca=src[i];
+ float ca = src[i];
float c;
- int ret;
- c=ca/alpha;
- if (alpha==0.0)
- ret=0;
+ int ret;
+ c = ca / alpha;
+ if (alpha == 0.0)
+ ret = 0;
else
ret = table_F_8g[gggl_float_to_index16 (c)];
- if (ret<=0)
- dst[i]=0;
- else if (ret>255)
- dst[i]=255;
+ if (ret <= 0)
+ dst[i] = 0;
+ else if (ret > 255)
+ dst[i] = 255;
else
dst[i] = ret;
}
{
- int t=dst[0];
- dst[0]=dst[2];
- dst[2]=t;
- dst[3]=255;
+ int t = dst[0];
+ dst[0] = dst[2];
+ dst[2] = t;
+ dst[3] = 255;
}
src += 4;
dst += 4;
unsigned char *dstc,
long samples)
{
- float *src = (void*)srcc;
- unsigned char *dst = (void*)dstc;
- long n=samples;
+ float *src = (void *) srcc;
+ unsigned char *dst = (void *) dstc;
+ long n = samples;
+
while (n--)
{
dst[0] = table_F_8g[gggl_float_to_index16 (src[2])];
dst[1] = table_F_8g[gggl_float_to_index16 (src[1])];
dst[2] = table_F_8g[gggl_float_to_index16 (src[0])];
- src += 4;
- dst += 4;
+ src += 4;
+ dst += 4;
}
return samples;
}
unsigned char *dstc,
long samples)
{
- float *src = (void*)srcc;
- unsigned char *dst = (void*)dstc;
- long n=samples;
+ float *src = (void *) srcc;
+ unsigned char *dst = (void *) dstc;
+ long n = samples;
+
while (n--)
{
float alpha = src[3];
if (alpha < 0.00001)
{
- dst[0]=0;
- dst[1]=0;
- dst[2]=0;
+ dst[0] = 0;
+ dst[1] = 0;
+ dst[2] = 0;
}
else
{
- float alpha_recip = 1.0/alpha;
- dst[0] = table_F_8g[gggl_float_to_index16 (src[0]*alpha_recip)];
- dst[1] = table_F_8g[gggl_float_to_index16 (src[1]*alpha_recip)];
- dst[2] = table_F_8g[gggl_float_to_index16 (src[2]*alpha_recip)];
+ float alpha_recip = 1.0 / alpha;
+ dst[0] = table_F_8g[gggl_float_to_index16 (src[0] * alpha_recip)];
+ dst[1] = table_F_8g[gggl_float_to_index16 (src[1] * alpha_recip)];
+ dst[2] = table_F_8g[gggl_float_to_index16 (src[2] * alpha_recip)];
}
src += 4;
dst += 3;
unsigned char *dstc,
long samples)
{
- unsigned char *src = (void*)srcc;
- unsigned char *dst = (void*)dstc;
- long n=samples;
+ unsigned char *src = (void *) srcc;
+ unsigned char *dst = (void *) dstc;
+ long n = samples;
+
while (n--)
{
- unsigned char alpha=src[3];
- dst[0]=alpha?(src[2]*255/alpha):0;
- dst[1]=alpha?(src[1]*255/alpha):0;
- dst[2]=alpha?(src[0]*255/alpha):0;
- dst[3]=alpha;
- src+=4;
- dst+=4;
+ unsigned char alpha = src[3];
+ dst[0] = alpha ? (src[2] * 255 / alpha) : 0;
+ dst[1] = alpha ? (src[1] * 255 / alpha) : 0;
+ dst[2] = alpha ? (src[0] * 255 / alpha) : 0;
+ dst[3] = alpha;
+ src += 4;
+ dst += 4;
}
return samples;
}
-#define conv_rgb8_rgbAF conv_rgb8_rgbaF
+#define conv_rgb8_rgbAF conv_rgb8_rgbaF
int init (void);
init (void)
{
Babl *rgbaF = babl_format_new (
- babl_model ("RGBA"),
- babl_type ("float"),
- babl_component ("R"),
- babl_component ("G"),
- babl_component ("B"),
- babl_component ("A"),
- NULL);
+ babl_model ("RGBA"),
+ babl_type ("float"),
+ babl_component ("R"),
+ babl_component ("G"),
+ babl_component ("B"),
+ babl_component ("A"),
+ NULL);
Babl *rgbAF = babl_format_new (
- babl_model ("RaGaBaA"),
- babl_type ("float"),
- babl_component ("Ra"),
- babl_component ("Ga"),
- babl_component ("Ba"),
- babl_component ("A"),
- NULL);
+ babl_model ("RaGaBaA"),
+ babl_type ("float"),
+ babl_component ("Ra"),
+ babl_component ("Ga"),
+ babl_component ("Ba"),
+ babl_component ("A"),
+ NULL);
Babl *rgba8 = babl_format_new (
- babl_model ("R'G'B'A"),
- babl_type ("u8"),
- babl_component ("R'"),
- babl_component ("G'"),
- babl_component ("B'"),
- babl_component ("A"),
- NULL);
+ babl_model ("R'G'B'A"),
+ babl_type ("u8"),
+ babl_component ("R'"),
+ babl_component ("G'"),
+ babl_component ("B'"),
+ babl_component ("A"),
+ NULL);
Babl *bgrA8 = babl_format_new (
- "name", "B'aG'aR'aA u8",
- babl_model ("R'aG'aB'aA"),
- babl_type ("u8"),
- babl_component ("B'a"),
- babl_component ("G'a"),
- babl_component ("R'a"),
- babl_component ("A"),
- NULL);
+ "name", "B'aG'aR'aA u8",
+ babl_model ("R'aG'aB'aA"),
+ babl_type ("u8"),
+ babl_component ("B'a"),
+ babl_component ("G'a"),
+ babl_component ("R'a"),
+ babl_component ("A"),
+ NULL);
Babl *rgb8 = babl_format_new (
- babl_model ("R'G'B'"),
- babl_type ("u8"),
- babl_component ("R'"),
- babl_component ("G'"),
- babl_component ("B'"),
- NULL);
+ babl_model ("R'G'B'"),
+ babl_type ("u8"),
+ babl_component ("R'"),
+ babl_component ("G'"),
+ babl_component ("B'"),
+ NULL);
Babl *sdl32 = babl_format_new (
- "name", "B'aG'aR'aPAD u8",
- babl_model ("R'G'B'"),
- babl_type ("u8"),
- babl_component ("B'"),
- babl_component ("G'"),
- babl_component ("R'"),
- babl_component ("PAD"),
- NULL);
+ "name", "B'aG'aR'aPAD u8",
+ babl_model ("R'G'B'"),
+ babl_type ("u8"),
+ babl_component ("B'"),
+ babl_component ("G'"),
+ babl_component ("R'"),
+ babl_component ("PAD"),
+ NULL);
table_init ();
-#define o(src,dst) \
- babl_conversion_new (src, dst, "linear", conv_##src##_##dst, NULL)
+#define o(src, dst) \
+ babl_conversion_new (src, dst, "linear", conv_ ## src ## _ ## dst, NULL)
o (rgb8, rgbaF);
o (rgb8, rgbAF);
#include "babl.h"
-#define INLINE inline
+#define INLINE inline
#include <math.h>
#include <stdio.h>
*
* due to ability to be able to relicence gggl under a different
* licence than GPL, I avoided the temptation to look at the
- * source files in the same location, in case I was going to
+ * source files in the same location, in case I was going to
* need this piece of code for projects where GPL compatibility
* was a must.
*
/* lookup tables used in conversion */
-static float table_8_F[1 << 8];
-static float table_16_F[1 << 16];
-static unsigned char table_F_8[1 << 16];
+static float table_8_F[1 << 8];
+static float table_16_F[1 << 16];
+static unsigned char table_F_8[1 << 16];
static unsigned short table_F_16[1 << 16];
/* fill tables for conversion from integer to float */
{
- int i;
+ int i;
for (i = 0; i < 1 << 8; i++)
{
table_8_F[i] = (i * 1.0) / 255.0;
{
union
{
- float f;
+ float f;
unsigned short s[2];
} u;
u.f = 0.0;
for (u.s[1] = 0; u.s[1] < 65535; u.s[1] += 1)
{
- unsigned char c;
+ unsigned char c;
unsigned short s;
if (u.f <= 0.0)
/ if (! ((*hi)%9))
/ fprintf (stderr, "\n"); */
- table_F_8[u.s[1]] = c;
+ table_F_8[u.s[1]] = c;
table_F_16[u.s[1]] = s;
}
}
/* fix tables to ensure 1:1 conversions back and forth */
if (0)
{ /*FIXME: probably not the right way to do it,.. must sit down and scribble on paper */
- int i;
+ int i;
for (i = 0; i < 256; i++)
{
- float f = table_8_F[i];
- unsigned short *hi = ((unsigned short *) (void*)&f);
- unsigned short *lo = ((unsigned short *) (void*)&f);
- *lo = 0;
+ float f = table_8_F[i];
+ unsigned short *hi = ((unsigned short *) (void *) &f);
+ unsigned short *lo = ((unsigned short *) (void *) &f);
+ *lo = 0;
table_F_8[(*hi)] = i;
}
}
{
union
{
- float f;
+ float f;
unsigned short s[2];
} u;
u.f = f;
static INLINE long
conv_F_8 (unsigned char *src, unsigned char *dst, long samples)
{
- long n=samples;
+ long n = samples;
+
if (!table_inited)
table_init ();
while (n--)
{
register float f = (*(float *) src);
*(unsigned char *) dst = table_F_8[gggl_float_to_index16 (f)];
- dst += 1;
- src += 4;
+ dst += 1;
+ src += 4;
}
return samples;
}
static INLINE long
conv_F_16 (unsigned char *src, unsigned char *dst, long samples)
{
- long n=samples;
+ long n = samples;
+
if (!table_inited)
table_init ();
while (n--)
{
register float f = (*(float *) src);
*(unsigned short *) dst = table_F_16[gggl_float_to_index16 (f)];
- dst += 2;
- src += 4;
+ dst += 2;
+ src += 4;
}
return samples;
}
static INLINE long
conv_8_F (unsigned char *src, unsigned char *dst, long samples)
{
- long n=samples;
+ long n = samples;
+
if (!table_inited)
table_init ();
while (n--)
{
(*(float *) dst) = table_8_F[*(unsigned char *) src];
- dst += 4;
- src += 1;
+ dst += 4;
+ src += 1;
}
return samples;
}
static INLINE long
conv_16_F (unsigned char *src, unsigned char *dst, long samples)
{
- long n=samples;
+ long n = samples;
+
if (!table_inited)
table_init ();
while (n--)
{
(*(float *) dst) = table_16_F[*(unsigned short *) src];
- dst += 4;
- src += 2;
+ dst += 4;
+ src += 2;
}
return samples;
}
static INLINE long
conv_F_8 (unsigned char *src, unsigned char *dst, long samples)
{
- long n=samples;
+ long n = samples;
+
while (n--)
{
- float f = ((*(float *) src));
+ float f = ((*(float *) src));
if (f < 0.0)
{
*(unsigned char *) dst = 0;
static INLINE long
conv_F_16 (unsigned char *src, unsigned char *dst, long samples)
{
- long n=samples;
+ long n = samples;
+
while (n--)
{
- float f = ((*(float *) src));
+ float f = ((*(float *) src));
if (f < 0.0)
{
*(unsigned short *) dst = 0;
static INLINE long
conv_8_F (unsigned char *src, unsigned char *dst, long samples)
{
- long n=samples;
+ long n = samples;
+
while (n--)
{
(*(float *) dst) = (*(unsigned char *) src / 255.0);
- dst += 4;
- src += 1;
+ dst += 4;
+ src += 1;
}
return samples;
}
static INLINE long
conv_16_F (unsigned char *src, unsigned char *dst, long samples)
{
- long n=samples;
+ long n = samples;
+
while (n--)
{
(*(float *) dst) = *(unsigned short *) src / 65535.0;
- dst += 4;
- src += 2;
+ dst += 4;
+ src += 2;
}
return samples;
}
static INLINE long
conv_F_D (unsigned char *src, unsigned char *dst, long samples)
{
- long n=samples;
+ long n = samples;
+
while (n--)
{
*(double *) dst = ((*(float *) src));
- dst += 8;
- src += 4;
+ dst += 8;
+ src += 4;
}
return samples;
}
static INLINE long
conv_D_F (unsigned char *src, unsigned char *dst, long samples)
{
- long n=samples;
+ long n = samples;
+
while (n--)
{
*(float *) dst = ((*(double *) src));
- dst += 4;
- src += 8;
+ dst += 4;
+ src += 8;
}
return samples;
}
static INLINE long
conv_16_8 (unsigned char *src, unsigned char *dst, long samples)
{
- long n=samples;
+ long n = samples;
+
while (n--)
{
(*(unsigned char *) dst) = (*(unsigned short *) src) >> 8;
- dst += 1;
- src += 2;
+ dst += 1;
+ src += 2;
}
return samples;
}
static INLINE long
conv_8_16 (unsigned char *src, unsigned char *dst, long samples)
{
- long n=samples;
+ long n = samples;
+
while (n--)
{
(*(unsigned short *) dst) = (*(unsigned char *) src) << 8;
- dst += 2;
- src += 1;
+ dst += 2;
+ src += 1;
}
return samples;
}
return samples;
}
-#define conv_rgbaF_rgbP8 conv_rgbaF_rgba8
+#define conv_rgbaF_rgbP8 conv_rgbaF_rgba8
static INLINE long
conv_rgbF_rgb8 (unsigned char *src, unsigned char *dst, long samples)
return samples;
}
-#define conv_rgbAF_rgbA8 conv_rgbaF_rgba8
-#define conv_gF_g8 conv_F_8
-#define conv_gAF_gA8 conv_gaF_ga8
+#define conv_rgbAF_rgbA8 conv_rgbaF_rgba8
+#define conv_gF_g8 conv_F_8
+#define conv_gAF_gA8 conv_gaF_ga8
static INLINE long
conv_rgbaF_rgba16 (unsigned char *src, unsigned char *dst, long samples)
return samples;
}
-#define conv_rgbAF_rgbAD conv_rgbaF_rgbaD
-#define conv_rgbAD_rgbAD conv_rgbaD_rgbaF
-#define conv_rgbAF_rgbA16 conv_rgbaF_rgba16
-#define conv_gF_g16 conv_F_16
-#define conv_gAF_gA16 conv_gaF_ga16
+#define conv_rgbAF_rgbAD conv_rgbaF_rgbaD
+#define conv_rgbAD_rgbAD conv_rgbaD_rgbaF
+#define conv_rgbAF_rgbA16 conv_rgbaF_rgba16
+#define conv_gF_g16 conv_F_16
+#define conv_gAF_gA16 conv_gaF_ga16
static INLINE long
conv_rgba8_rgbaF (unsigned char *src, unsigned char *dst, long samples)
return samples;
}
-#define conv_rgbA8_rgbAF conv_rgba8_rgbaF
-#define conv_gA8_gAF conv_ga8_gaF
-#define conv_g8_gF conv_8_F
+#define conv_rgbA8_rgbAF conv_rgba8_rgbaF
+#define conv_gA8_gAF conv_ga8_gaF
+#define conv_g8_gF conv_8_F
static INLINE long
conv_rgba16_rgbaF (unsigned char *src, unsigned char *dst, long samples)
return samples;
}
-#define conv_rgbA16_rgbAF conv_rgba16_rgbaF
-#define conv_gA16_gAF conv_ga16_gaF
-#define conv_g16_gF conv_16_F
+#define conv_rgbA16_rgbAF conv_rgba16_rgbaF
+#define conv_gA16_gAF conv_ga16_gaF
+#define conv_g16_gF conv_16_F
static INLINE long
conv_rgba16_rgba8 (unsigned char *src, unsigned char *dst, long samples)
return samples;
}
-#define conv_rgbA16_rgbA8 conv_rgba16_rgba8
-#define conv_gA16_gA8 conv_ga16_ga8
-#define conv_g16_g8 conv_16_8
+#define conv_rgbA16_rgbA8 conv_rgba16_rgba8
+#define conv_gA16_gA8 conv_ga16_ga8
+#define conv_g16_g8 conv_16_8
static INLINE long
conv_rgba8_rgba16 (unsigned char *src, unsigned char *dst, long samples)
return samples;
}
-#define conv_rgbA8_rgbA16 conv_rgba8_rgba16
-#define conv_gA8_gA16 conv_ga8_ga16
-#define conv_g8_g16 conv_8_16
+#define conv_rgbA8_rgbA16 conv_rgba8_rgba16
+#define conv_gA8_gA16 conv_ga8_ga16
+#define conv_g8_g16 conv_8_16
/* alpha conversions */
static INLINE long
conv_gaF_gAF (unsigned char *src, unsigned char *dst, long samples)
{
- long n=samples;
+ long n = samples;
+
while (n--)
{
- float alpha = (*(float *) (src + 4));
+ float alpha = (*(float *) (src + 4));
*(float *) dst = ((*(float *) src) * alpha);
- dst += 4;
- src += 4;
+ dst += 4;
+ src += 4;
*(float *) dst = alpha;
- dst += 4;
- src += 4;
+ dst += 4;
+ src += 4;
}
return samples;
}
static INLINE long
conv_gAF_gaF (unsigned char *src, unsigned char *dst, long samples)
{
- long n=samples;
+ long n = samples;
+
while (n--)
{
- float alpha = (*(float *) (src + 4));
+ float alpha = (*(float *) (src + 4));
*(float *) dst = ((*(float *) src) / alpha);
- dst += 4;
- src += 4;
+ dst += 4;
+ src += 4;
*(float *) dst = alpha;
- dst += 4;
- src += 4;
+ dst += 4;
+ src += 4;
}
return samples;
}
static INLINE long
conv_rgbAF_rgbaF (unsigned char *src, unsigned char *dst, long samples)
{
- long n=samples;
+ long n = samples;
+
while (n--)
{
- float alpha = (*(float *) (src + 4 * 3));
- int c;
+ float alpha = (*(float *) (src + 4 * 3));
+ int c;
if (alpha >= 1.0)
{
for (c = 0; c < 3; c++)
{
*(float *) dst = *(float *) src;
- dst += 4;
- src += 4;
+ dst += 4;
+ src += 4;
}
}
else if (alpha <= 0.0)
for (c = 0; c < 3; c++)
{
*(float *) dst = 0;
- dst += 4;
- src += 4;
+ dst += 4;
+ src += 4;
}
}
else
for (c = 0; c < 3; c++)
{
*(float *) dst = ((*(float *) src) / alpha);
- dst += 4;
- src += 4;
+ dst += 4;
+ src += 4;
}
}
*(float *) dst = alpha;
- dst += 4;
- src += 4;
+ dst += 4;
+ src += 4;
}
return samples;
}
static INLINE long
conv_rgbaF_rgbAF (unsigned char *src, unsigned char *dst, long samples)
{
- long n=samples;
+ long n = samples;
+
while (n--)
{
- float alpha = (*(float *) (src + 4 * 3));
- int c;
+ float alpha = (*(float *) (src + 4 * 3));
+ int c;
if (alpha >= 1.0)
{
for (c = 0; c < 3; c++)
{
*(float *) dst = *(float *) src;
- dst += 4;
- src += 4;
+ dst += 4;
+ src += 4;
}
}
else if (alpha <= 0.0)
for (c = 0; c < 3; c++)
{
*(float *) dst = 0;
- dst += 4;
- src += 4;
+ dst += 4;
+ src += 4;
}
}
else
for (c = 0; c < 3; c++)
{
*(float *) dst = ((*(float *) src) * alpha);
- dst += 4;
- src += 4;
+ dst += 4;
+ src += 4;
}
}
*(float *) dst = alpha;
- dst += 4;
- src += 4;
+ dst += 4;
+ src += 4;
}
return samples;
}
static INLINE long
conv_rgbaF_rgbF (unsigned char *src, unsigned char *dst, long samples)
{
- long n=samples;
+ long n = samples;
+
while (n--)
{
*(int *) dst = (*(int *) src);
- dst += 4;
- src += 4;
+ dst += 4;
+ src += 4;
*(int *) dst = (*(int *) src);
- dst += 4;
- src += 4;
+ dst += 4;
+ src += 4;
*(int *) dst = (*(int *) src);
- dst += 4;
- src += 4;
- src += 4;
+ dst += 4;
+ src += 4;
+ src += 4;
}
return samples;
}
static INLINE long
conv_rgbF_rgbaF (unsigned char *src, unsigned char *dst, long samples)
{
- long n=samples;
+ long n = samples;
+
while (n--)
{
- *(int *) dst = (*(int *) src);
- dst += 4;
- src += 4;
- *(int *) dst = (*(int *) src);
- dst += 4;
- src += 4;
- *(int *) dst = (*(int *) src);
- dst += 4;
- src += 4;
+ *(int *) dst = (*(int *) src);
+ dst += 4;
+ src += 4;
+ *(int *) dst = (*(int *) src);
+ dst += 4;
+ src += 4;
+ *(int *) dst = (*(int *) src);
+ dst += 4;
+ src += 4;
*(float *) dst = 1.0;
- dst += 4;
+ dst += 4;
}
return samples;
}
static INLINE long
conv_gaF_gF (unsigned char *src, unsigned char *dst, long samples)
{
- long n=samples;
+ long n = samples;
+
while (n--)
{
*(int *) dst = (*(int *) src);
- dst += 4;
- src += 4;
- src += 4;
+ dst += 4;
+ src += 4;
+ src += 4;
}
return samples;
}
static INLINE long
conv_gF_gaF (unsigned char *src, unsigned char *dst, long samples)
{
- long n=samples;
+ long n = samples;
+
while (n--)
{
- *(int *) dst = (*(int *) src);
- dst += 4;
- src += 4;
+ *(int *) dst = (*(int *) src);
+ dst += 4;
+ src += 4;
*(float *) dst = 1.0;
- dst += 4;
+ dst += 4;
}
return samples;
}
-#define conv_gAF_gF conv_gaF_gF
-#define conv_gF_gAF conv_gF_gaF
+#define conv_gAF_gF conv_gaF_gF
+#define conv_gF_gAF conv_gF_gaF
-#define conv_rgbAF_rgbF conv_rgbaF_rgbF
-#define conv_rgbF_rgbAF conv_rgbF_rgbaF
+#define conv_rgbAF_rgbF conv_rgbaF_rgbF
+#define conv_rgbF_rgbAF conv_rgbF_rgbaF
/* colorchannel dropping and adding */
static INLINE long
conv_gF_rgbF (unsigned char *src, unsigned char *dst, long samples)
{
- long n=samples;
+ long n = samples;
+
while (n--)
{
- int c;
+ int c;
for (c = 0; c < 3; c++)
{
(*(int *) dst) = (*(int *) src);
- dst += 4;
+ dst += 4;
}
src += 4;
}
static INLINE long
conv_rgbF_gF (unsigned char *src, unsigned char *dst, long samples)
{
- long n=samples;
+ long n = samples;
+
while (n--)
{
- int c;
- float sum = 0;
+ int c;
+ float sum = 0;
for (c = 0; c < 3; c++)
{
sum += (*(float *) src);
src += 4;
}
- sum /= 3;
+ sum /= 3;
(*(float *) dst) = sum;
- dst += 4;
+ dst += 4;
}
return samples;
}
static INLINE long
conv_gaF_rgbaF (unsigned char *src, unsigned char *dst, long samples)
{
- long n=samples;
+ long n = samples;
+
while (n--)
{
- int c;
+ int c;
for (c = 0; c < 3; c++)
{
(*(int *) dst) = (*(int *) src);
- dst += 4;
+ dst += 4;
}
- src += 4;
+ src += 4;
(*(int *) dst) = (*(int *) src);
- dst += 4;
- src += 4;
+ dst += 4;
+ src += 4;
}
return samples;
}
static INLINE long
conv_rgbaF_gaF (unsigned char *src, unsigned char *dst, long samples)
{
- long n=samples;
+ long n = samples;
+
while (n--)
{
- int c;
- float sum = 0;
+ int c;
+ float sum = 0;
for (c = 0; c < 3; c++)
{
src += 4;
}
(*(float *) dst) = sum / 3;
- dst += 4;
- (*(int *) dst) = (*(int *) src);
- dst += 4;
- src += 4;
-
+ dst += 4;
+ (*(int *) dst) = (*(int *) src);
+ dst += 4;
+ src += 4;
}
return samples;
}
-#define conv_gAF_rgbAF conv_gaF_rgbaF
-#define conv_rgbAF_gAF conv_rgbaF_gaF
+#define conv_gAF_rgbAF conv_gaF_rgbaF
+#define conv_rgbAF_gAF conv_rgbaF_gaF
/* other conversions coded for some optimisation reason or sumthin */
static INLINE long
conv_rgbA8_rgbaF (unsigned char *src, unsigned char *dst, long samples)
{
- long n=samples;
+ long n = samples;
+
while (n--)
{
- float alpha = (*(unsigned char *) src + (3)) / 255.0;
- int c;
+ float alpha = (*(unsigned char *) src + (3)) / 255.0;
+ int c;
for (c = 0; c < 3; c++)
{
(*(float *) dst) = (*(unsigned char *) src / 255.0) / alpha;
- dst += 4;
- src += 1;
+ dst += 4;
+ src += 1;
}
*(float *) dst = alpha;
- dst += 4;
- src += 1;
+ dst += 4;
+ src += 1;
}
return samples;
}
static INLINE long
conv_rgbaF_rgbA8 (unsigned char *src, unsigned char *dst, long samples)
{
- long n=samples;
+ long n = samples;
+
while (n--)
{
- float alpha = (*(float *) (src + (4 * 3)));
- int c;
+ float alpha = (*(float *) (src + (4 * 3)));
+ int c;
for (c = 0; c < 3; c++)
{
*(unsigned char *) dst = ((*(float *) src) * alpha) * 255.0;
- dst += 1;
- src += 4;
+ dst += 1;
+ src += 4;
}
*(unsigned char *) dst = alpha * 255.0;
dst++;
static INLINE long
conv_rgbaF_rgbA16 (unsigned char *src, unsigned char *dst, long samples)
{
- long n=samples;
+ long n = samples;
+
while (n--)
{
- float alpha = (*(float *) src + (4 * 3));
- int c;
+ float alpha = (*(float *) src + (4 * 3));
+ int c;
for (c = 0; c < 3; c++)
{
*(unsigned short *) dst = ((*(float *) src) * alpha) * 65535.0;
- dst += 2;
- src += 4;
+ dst += 2;
+ src += 4;
}
*(unsigned short *) dst = alpha * 65535.0;
- dst += 2;
- src += 4;
+ dst += 2;
+ src += 4;
}
return samples;
}
static INLINE long
conv_rgbaF_rgb8 (unsigned char *src, unsigned char *dst, long samples)
{
- long n=samples;
+ long n = samples;
+
while (n--)
{
- int c;
+ int c;
for (c = 0; c < 3; c++)
{
*(unsigned char *) dst = (*(float *) src) * 255.0;
- dst += 1;
- src += 4;
+ dst += 1;
+ src += 4;
}
src += 4;
}
static INLINE long
conv_rgbaF_g8 (unsigned char *src, unsigned char *dst, long samples)
{
- long n=samples;
+ long n = samples;
+
while (n--)
{
- int c;
- float sum = 0;
+ int c;
+ float sum = 0;
for (c = 0; c < 3; c++)
{
static INLINE long
conv_rgbaF_rgb16 (unsigned char *src, unsigned char *dst, long samples)
{
- long n=samples;
+ long n = samples;
+
while (n--)
{
- int c;
+ int c;
for (c = 0; c < 3; c++)
{
*(unsigned short *) dst = (*(float *) src) * 65535.0;
- dst += 2;
- src += 4;
+ dst += 2;
+ src += 4;
}
src += 4;
}
static INLINE long
conv_rgbP8_rgbaF (unsigned char *src, unsigned char *dst, long samples)
{
- long n=samples;
+ long n = samples;
+
while (n--)
{
- int c;
+ int c;
for (c = 0; c < 3; c++)
{
(*(float *) dst) = *(unsigned char *) src / 255.0;
- dst += 4;
- src += 1;
+ dst += 4;
+ src += 1;
}
(*(float *) dst) = 1.0;
- dst += 4;
- src += 1;
+ dst += 4;
+ src += 1;
}
return samples;
}
static INLINE long
conv_rgbA16_rgbaF (unsigned char *src, unsigned char *dst, long samples)
{
- long n=samples;
+ long n = samples;
+
while (n--)
{
- float alpha = (*(unsigned short *) src + (3)) / 65535.0;
- int c;
+ float alpha = (*(unsigned short *) src + (3)) / 65535.0;
+ int c;
for (c = 0; c < 3; c++)
{
(*(float *) dst) = (*(unsigned short *) src / 65535.0) / alpha;
- dst += 4;
- src += 2;
+ dst += 4;
+ src += 2;
}
*(float *) dst = alpha;
- dst += 4;
- src += 2;
+ dst += 4;
+ src += 2;
}
return samples;
}
/*
-static INLINE long
-conv_rgb8_rgbaF (unsigned char *src,
+ static INLINE long
+ conv_rgb8_rgbaF (unsigned char *src,
unsigned char *dst,
int samples)
-{
+ {
long n=samples;
while (n--) {
int c;
-
+
for (c = 0; c < 3; c++) {
(*(float *) dst) = *(unsigned char *) src / 255.0;
dst += 4;
(*(float *) dst) = 1.0;
dst += 4;
}
- return samples;
-}
-
-static INLINE long
-conv_g8_rgbaF (unsigned char *src,
+ return samples;
+ }
+
+ static INLINE long
+ conv_g8_rgbaF (unsigned char *src,
unsigned char *dst,
int samples)
-{
+ {
long n=samples;
while (n--) {
int c;
(*(float *) dst) = 1.0;
dst += 4;
}
- return samples;
-}
+ return samples;
+ }
-static INLINE long
-conv_rgb16_rgbaF (unsigned char *src,
+ static INLINE long
+ conv_rgb16_rgbaF (unsigned char *src,
unsigned char *dst,
int samples)
-{
+ {
long n=samples;
while (n--) {
int c;
for (c = 0; c < 3; c++) {
- *(float *) dst = (*(unsigned short *) src) / 65535.0;
+ *(float *) dst = (*(unsigned short *) src) / 65535.0;
src += 2;
dst += 4;
}
- *(float *) dst = 1.0;
+ *(float *) dst = 1.0;
src += 2;
dst += 4;
}
- return samples;
-}
+ return samples;
+ }
-static INLINE long
-conv_gF_rgbaF (unsigned char *src,
+ static INLINE long
+ conv_gF_rgbaF (unsigned char *src,
unsigned char *dst,
int samples)
-{
+ {
long n=samples;
while (n--) {
(*(float *) dst) = (*(float *) src);
src += 4;
}
- return samples;
-}
-*/
+ return samples;
+ }
+ */
static INLINE long
conv_rgba8_rgbA8 (unsigned char *src, unsigned char *dst, long samples)
{
- long n=samples;
+ long n = samples;
+
while (n--)
{
if (src[3] == 255)
static INLINE long
conv_rgbA8_rgba8 (unsigned char *src, unsigned char *dst, long samples)
{
- long n=samples;
+ long n = samples;
+
while (n--)
{
if (src[3] == 255)
{
*(unsigned int *) dst = *(unsigned int *) src;
- dst += 4;
+ dst += 4;
}
else if (src[3] == 0)
{
*(unsigned int *) dst = 0;
- dst += 4;
+ dst += 4;
}
else
{
static INLINE long
conv_argb8_rgba8 (unsigned char *src, unsigned char *dst, long samples)
{
- long n=samples;
+ long n = samples;
+
while (n--)
{
dst[0] = src[2];
dst[1] = src[1];
dst[2] = src[0];
dst[3] = src[3];
- src += 4;
- dst += 4;
+ src += 4;
+ dst += 4;
}
return samples;
}
static INLINE long
conv_rgba8_argb8 (unsigned char *src, unsigned char *dst, long samples)
{
- long n=samples;
+ long n = samples;
+
while (n--)
{
dst[0] = src[3];
dst[1] = src[0];
dst[2] = src[1];
dst[3] = src[2];
- src += 4;
- dst += 4;
+ src += 4;
+ dst += 4;
}
return samples;
}
static INLINE long
conv_Argb8_rgbA8 (unsigned char *src, unsigned char *dst, long samples)
{
- long n=samples;
+ long n = samples;
+
while (n--)
{
dst[0] = src[2];
dst[1] = src[1];
dst[2] = src[0];
dst[3] = src[3];
- src += 4;
- dst += 4;
+ src += 4;
+ dst += 4;
}
return samples;
}
static INLINE long
conv_rgbA8_Argb8 (unsigned char *src, unsigned char *dst, long samples)
{
- long n=samples;
+ long n = samples;
+
while (n--)
{
dst[0] = src[2];
dst[1] = src[1];
dst[2] = src[0];
dst[3] = src[3];
- src += 4;
- dst += 4;
+ src += 4;
+ dst += 4;
}
return samples;
}
static INLINE long
conv_Prgb8_rgbP8 (unsigned char *src, unsigned char *dst, long samples)
{
- long n=samples;
+ long n = samples;
+
while (n--)
{
dst[0] = src[2];
dst[1] = src[1];
dst[2] = src[0];
dst[3] = 255;
- src += 4;
- dst += 4;
+ src += 4;
+ dst += 4;
}
return samples;
}
static INLINE long
conv_rgbP8_Prgb8 (unsigned char *src, unsigned char *dst, long samples)
{
- long n=samples;
+ long n = samples;
+
while (n--)
{
dst[0] = src[2];
dst[1] = src[1];
dst[2] = src[0];
dst[3] = 255;
- src += 4;
- dst += 4;
+ src += 4;
+ dst += 4;
}
return samples;
}
static INLINE long
conv_Prgb8_rgb8 (unsigned char *src, unsigned char *dst, long samples)
{
- long n=samples;
+ long n = samples;
+
while (n--)
{
dst[0] = src[2];
static INLINE long
conv_rgb8_Prgb8 (unsigned char *src, unsigned char *dst, long samples)
{
- long n=samples;
+ long n = samples;
+
while (n--)
{
dst[0] = src[2]; /* blue */
dst[1] = src[1]; /* green */
dst[2] = src[0]; /* red */
dst[3] = 255;
- src += 3;
- dst += 4;
+ src += 3;
+ dst += 4;
}
return samples;
}
static INLINE long
conv_rgbA16_rgba16 (unsigned char *src, unsigned char *dst, long samples)
{
- long n=samples;
+ long n = samples;
+
while (n--)
{
if (src[3])
(((unsigned short *) src)[2] * 65535) / src[3];
}
((unsigned short *) dst)[3] = ((unsigned short *) src)[3];
- dst += 8;
- src += 8;
+ dst += 8;
+ src += 8;
}
return samples;
}
static INLINE long
conv_rgb8_rgbP8 (unsigned char *src, unsigned char *dst, long samples)
{
- long n=samples;
+ long n = samples;
+
while (n--)
{
dst[0] = src[0];
dst[1] = src[1];
dst[2] = src[2];
- src += 3;
- dst += 4;
+ src += 3;
+ dst += 4;
}
return samples;
}
static INLINE long
conv_rgb8_rgba8 (unsigned char *src, unsigned char *dst, long samples)
{
- long n=samples;
+ long n = samples;
+
while (n--)
{
dst[0] = src[0];
dst[1] = src[1];
dst[2] = src[2];
dst[3] = 255;
- src += 3;
- dst += 4;
+ src += 3;
+ dst += 4;
}
return samples;
}
-#define conv_rgb8_rgbA8 conv_rgb8_rgba8
+#define conv_rgb8_rgbA8 conv_rgb8_rgba8
static INLINE long
conv_rgbP8_rgba8 (unsigned char *src, unsigned char *dst, long samples)
{
- long n=samples;
+ long n = samples;
+
while (n--)
{
*(unsigned int *) dst = *(unsigned int *) src;
- dst[3] = 255;
- src += 4;
- dst += 4;
+ dst[3] = 255;
+ src += 4;
+ dst += 4;
}
return samples;
}
-#define conv_rgbP8_rgbA8 conv_rgbP8_rgba8
+#define conv_rgbP8_rgbA8 conv_rgbP8_rgba8
static INLINE long
conv_rgba8_rgbP8 (unsigned char *src, unsigned char *dst, long samples)
return samples;
}
-#define conv_rgbA8_rgbP8 conv_rgba8_rgbP8
+#define conv_rgbA8_rgbP8 conv_rgba8_rgbP8
static INLINE long
conv_rgbP8_rgb8 (unsigned char *src, unsigned char *dst, long samples)
{
- long n=samples;
+ long n = samples;
+
while (n--)
{
dst[0] = src[0];
dst[1] = src[1];
dst[2] = src[2];
- src += 4;
- dst += 3;
+ src += 4;
+ dst += 3;
}
return samples;
}
static INLINE long
conv_rgba8_rgb8 (unsigned char *src, unsigned char *dst, long samples)
{
- long n=samples;
+ long n = samples;
+
while (n--)
{
dst[0] = src[0];
dst[1] = src[1];
dst[2] = src[2];
- src += 4;
- dst += 3;
+ src += 4;
+ dst += 3;
}
return samples;
}
-#define conv_rgbA8_rgb8 conv_rgbP8_rgb8
+#define conv_rgbA8_rgb8 conv_rgbP8_rgb8
#ifndef byteclamp
-#define byteclamp(j) do{if(j<0)j=0; else if(j>255)j=255;}while(0)
+#define byteclamp(j) do { if (j < 0) j = 0;else if (j > 255) j = 255; } while (0)
#endif
-#define YUV82RGB8(Y,U,V,R,G,B)do{\
- R= ((Y<<15) + 37355*(V-128))>>15;\
- G= ((Y<<15) -12911* (U-128) - 19038*(V-128))>>15;\
- B= ((Y<<15) +66454* (U-128) )>>15;\
- byteclamp(R);\
- byteclamp(G);\
- byteclamp(B);\
-}while(0)
-
-#define RGB82YUV8(R,G,B,Y,U,V)do{\
- Y= (( 9798*R + 19234*G + 3736*B)>>15) +000;\
- U= ((-4817*R - 9470*G + 14320*B)>>15) +128;\
- V= (( 20152*R - 16875*G - 3277*B)>>15) +128;\
- byteclamp(Y);\
- byteclamp(U);\
- byteclamp(V);\
-}while(0)
+#define YUV82RGB8(Y, U, V, R, G, B) do { \
+ R = ((Y << 15) + 37355 * (V - 128)) >> 15; \
+ G = ((Y << 15) - 12911 * (U - 128) - 19038 * (V - 128)) >> 15; \
+ B = ((Y << 15) + 66454 * (U - 128)) >> 15; \
+ byteclamp (R); \
+ byteclamp (G); \
+ byteclamp (B); \
+ } while (0)
+
+#define RGB82YUV8(R, G, B, Y, U, V) do { \
+ Y = ((9798 * R + 19234 * G + 3736 * B) >> 15) + 000; \
+ U = ((-4817 * R - 9470 * G + 14320 * B) >> 15) + 128; \
+ V = ((20152 * R - 16875 * G - 3277 * B) >> 15) + 128; \
+ byteclamp (Y); \
+ byteclamp (U); \
+ byteclamp (V); \
+ } while (0)
static INLINE long
conv_yuv8_rgb8 (unsigned char *src, unsigned char *dst, long samples)
{
- long n=samples;
+ long n = samples;
+
while (n--)
{
- int R, G, B;
+ int R, G, B;
YUV82RGB8 (src[0], src[1], src[2], R, G, B);
dst[0] = R;
dst[1] = G;
dst[2] = B;
- src += 3;
- dst += 3;
+ src += 3;
+ dst += 3;
}
return samples;
}
static INLINE long
conv_rgb8_yuv8 (unsigned char *src, unsigned char *dst, long samples)
{
- long n=samples;
+ long n = samples;
+
while (n--)
{
- int Y, U, V;
+ int Y, U, V;
YUV82RGB8 (src[0], src[1], src[2], Y, U, V);
dst[0] = Y;
dst[1] = U;
dst[2] = V;
- src += 3;
- dst += 3;
+ src += 3;
+ dst += 3;
}
return samples;
}
static INLINE long
conv_rgbaF_yuvaF (unsigned char *src, unsigned char *dst, long samples)
{
- float *src_f = (float *) src;
- float *dst_f = (float *) dst;
- long n=samples;
+ float *src_f = (float *) src;
+ float *dst_f = (float *) dst;
+ long n = samples;
+
while (n--)
{
- float R, G, B;
- float Y, U, V;
+ float R, G, B;
+ float Y, U, V;
R = src_f[0];
G = src_f[1];
B = src_f[2];
Y = 0.299 * R + 0.587 * B + 0.114 * B;
- U = (-0.1687) * R - 0.3313 * G + 0.5 * B /* +0.5 */ ;
- V = 0.5 * R - 0.4187 * G - 0.0813 * B /* +0.5 */ ;
+ U = (-0.1687) * R - 0.3313 * G + 0.5 * B /* +0.5 */;
+ V = 0.5 * R - 0.4187 * G - 0.0813 * B /* +0.5 */;
dst_f[0] = Y;
dst_f[1] = U;
static INLINE long
conv_yuvaF_rgbaF (unsigned char *src, unsigned char *dst, long samples)
{
- float *src_f = (float *) src;
- float *dst_f = (float *) dst;
- long n=samples;
+ float *src_f = (float *) src;
+ float *dst_f = (float *) dst;
+ long n = samples;
+
while (n--)
{
- float Y, U, V;
- float R, G, B;
+ float Y, U, V;
+ float R, G, B;
Y = src_f[0];
U = src_f[1];
V = src_f[2];
- R = Y + 1.40200 * (V /*-0.5*/ );
- G = Y - 0.34414 * (U /*-0.5*/ ) - 0.71414 * (V /*-0.5*/ );
- B = Y + 1.77200 * (U /*-0.5*/ );
+ R = Y + 1.40200 * (V /*-0.5*/);
+ G = Y - 0.34414 * (U /*-0.5*/) -0.71414 * (V /*-0.5*/);
+ B = Y + 1.77200 * (U /*-0.5*/);
dst_f[0] = R;
dst_f[1] = G;
static INLINE long
conv_rgbF_yuvF (unsigned char *src, unsigned char *dst, long samples)
{
- float *src_f = (float *) src;
- float *dst_f = (float *) dst;
- long n=samples;
+ float *src_f = (float *) src;
+ float *dst_f = (float *) dst;
+ long n = samples;
+
while (n--)
{
- float R, G, B;
- float Y, U, V;
+ float R, G, B;
+ float Y, U, V;
R = src_f[0];
G = src_f[1];
B = src_f[2];
Y = 0.299 * R + 0.587 * B + 0.114 * B;
- U = (-0.1687) * R - 0.3313 * G + 0.5 * B /* +0.5 */ ;
- V = 0.5 * R - 0.4187 * G - 0.0813 * B /* +0.5 */ ;
+ U = (-0.1687) * R - 0.3313 * G + 0.5 * B /* +0.5 */;
+ V = 0.5 * R - 0.4187 * G - 0.0813 * B /* +0.5 */;
dst_f[0] = Y;
dst_f[1] = U;
static INLINE long
conv_yuvF_rgbF (unsigned char *src, unsigned char *dst, long samples)
{
- float *src_f = (float *) src;
- float *dst_f = (float *) dst;
- long n=samples;
+ float *src_f = (float *) src;
+ float *dst_f = (float *) dst;
+ long n = samples;
+
while (n--)
{
- float Y, U, V;
- float R, G, B;
+ float Y, U, V;
+ float R, G, B;
Y = src_f[0];
U = src_f[1];
V = src_f[2];
- R = Y + 1.40200 * (V /*-0.5*/ );
- G = Y - 0.34414 * (U /*-0.5*/ ) - 0.71414 * (V /*-0.5*/ );
- B = Y + 1.77200 * (U /*-0.5*/ );
+ R = Y + 1.40200 * (V /*-0.5*/);
+ G = Y - 0.34414 * (U /*-0.5*/) -0.71414 * (V /*-0.5*/);
+ B = Y + 1.77200 * (U /*-0.5*/);
dst_f[0] = R;
dst_f[1] = G;
#include <math.h>
/*
-static const double Xn = 0.951;
-static const double Yn = 1.0;
-static const double Zn = 1.089;
-*/
+ static const double Xn = 0.951;
+ static const double Yn = 1.0;
+ static const double Zn = 1.089;
+ */
-#define LXN 0.312713F
-#define LYN 0.329016F
+#define LXN 0.312713F
+#define LYN 0.329016F
static const double lxn = LXN;
static const double lyn = LYN;
-static double xnn = LXN / LYN;
-static double znn = (1.0F - (LXN + LYN)) / LYN;
+static double xnn = LXN / LYN;
+static double znn = (1.0F - (LXN + LYN)) / LYN;
static const double LRAMP = 7.99959199F;
static INLINE long
conv_rgbF_xyzF (unsigned char *src, unsigned char *dst, long samples)
{
- float *src_f = (float *) src;
- float *dst_f = (float *) dst;
- long n=samples;
+ float *src_f = (float *) src;
+ float *dst_f = (float *) dst;
+ long n = samples;
+
while (n--)
{
- float x, y, z;
- float red, green, blue;
+ float x, y, z;
+ float red, green, blue;
- red = src_f[0];
+ red = src_f[0];
green = src_f[1];
- blue = src_f[2];
+ blue = src_f[2];
x = 0.431 * red + 0.342 * green + 0.179 * blue;
y = 0.222 * red + 0.707 * green + 0.071 * blue;
dst_f[0] = x;
dst_f[1] = y;
dst_f[2] = z;
- dst_f += 3;
- src_f += 3;
+ dst_f += 3;
+ src_f += 3;
}
return samples;
}
static INLINE long
conv_xyzF_rgbF (unsigned char *src, unsigned char *dst, long samples)
{
- float *src_f = (float *) src;
- float *dst_f = (float *) dst;
- long n=samples;
+ float *src_f = (float *) src;
+ float *dst_f = (float *) dst;
+ long n = samples;
+
while (n--)
{
dst_f[0] = src_f[0];
dst_f[1] = src_f[1];
dst_f[2] = src_f[2];
- dst_f += 3;
- src_f += 3;
+ dst_f += 3;
+ src_f += 3;
}
return samples;
}
static INLINE long
conv_labF_xyzF (unsigned char *src, unsigned char *dst, long samples)
{
- float *src_f = (float *) src;
- float *dst_f = (float *) dst;
- long n=samples;
+ float *src_f = (float *) src;
+ float *dst_f = (float *) dst;
+ long n = samples;
+
while (n--)
{
- float P;
- float X, Y, Z;
- float L, a, b;
+ float P;
+ float X, Y, Z;
+ float L, a, b;
L = src_f[0];
a = src_f[1];
}
X = (P + a / 500.0F);
- X = xnn * ffunc_inv (X);
+ X = xnn *ffunc_inv (X);
Z = (P - b / 200.0F);
- Z = znn * ffunc_inv (Z);
+ Z = znn *ffunc_inv (Z);
dst_f[0] = X;
dst_f[1] = Y;
dst_f[2] = Z;
- dst_f += 3;
- src_f += 3;
+ dst_f += 3;
+ src_f += 3;
}
return samples;
}
static INLINE long
conv_xyzF_labF (unsigned char *src, unsigned char *dst, long samples)
{
- float *src_f = (float *) src;
- float *dst_f = (float *) dst;
- long n=samples;
+ float *src_f = (float *) src;
+ float *dst_f = (float *) dst;
+ long n = samples;
+
while (n--)
{
- double ffuncY;
- float X, Y, Z;
- float L, a, b;
+ double ffuncY;
+ float X, Y, Z;
+ float L, a, b;
X = src_f[0];
Y = src_f[1];
Z = src_f[2];
}
ffuncY = ffunc (Y);
- a = 500.0F * (ffunc (X / xnn) - ffuncY);
- b = 200.0F * (ffuncY - ffunc (Z / znn));
+ a = 500.0F * (ffunc (X / xnn) - ffuncY);
+ b = 200.0F * (ffuncY - ffunc (Z / znn));
dst_f[0] = L;
dst_f[1] = a;
dst_f[2] = b;
- dst_f += 3;
- src_f += 3;
+ dst_f += 3;
+ src_f += 3;
}
return samples;
}
/******* end of cpercep lift out **/
-#define MAX_CONVERSIONS 100
+#define MAX_CONVERSIONS 100
typedef struct Conversion
{
- int from_fmt;
- int to_fmt;
- int cost; /* cost of function,. calculated as ms to convert 1024*1024 samples */
- int loss; /* 0 maps ok, 1 precision loss, 2 alpha loss, 4 channel loss
+ int from_fmt;
+ int to_fmt;
+ int cost; /* cost of function,. calculated as ms to convert 1024*1024 samples */
+ int loss; /* 0 maps ok, 1 precision loss, 2 alpha loss, 4 channel loss
(should be dwelled further into) */
- void (*function) (unsigned char *src, unsigned char *dst, long samples);
+ void (*function)(unsigned char *src, unsigned char *dst, long samples);
} Conversion;
init (void)
{
Babl *rgbaF = babl_format_new (
- babl_model ("RGBA"),
- babl_type ("float"),
- babl_component ("R"),
- babl_component ("G"),
- babl_component ("B"),
- babl_component ("A"),
- NULL);
+ babl_model ("RGBA"),
+ babl_type ("float"),
+ babl_component ("R"),
+ babl_component ("G"),
+ babl_component ("B"),
+ babl_component ("A"),
+ NULL);
Babl *rgba16 = babl_format_new (
- babl_model ("RGBA"),
- babl_type ("u16"),
- babl_component ("R"),
- babl_component ("G"),
- babl_component ("B"),
- babl_component ("A"),
- NULL);
+ babl_model ("RGBA"),
+ babl_type ("u16"),
+ babl_component ("R"),
+ babl_component ("G"),
+ babl_component ("B"),
+ babl_component ("A"),
+ NULL);
Babl *rgbaD = babl_format_new (
- babl_model ("RGBA"),
- babl_type ("double"),
- babl_component ("R"),
- babl_component ("G"),
- babl_component ("B"),
- babl_component ("A"),
- NULL);
+ babl_model ("RGBA"),
+ babl_type ("double"),
+ babl_component ("R"),
+ babl_component ("G"),
+ babl_component ("B"),
+ babl_component ("A"),
+ NULL);
Babl *rgba8 = babl_format_new (
- babl_model ("RGBA"),
- babl_type ("u8"),
- babl_component ("R"),
- babl_component ("G"),
- babl_component ("B"),
- babl_component ("A"),
- NULL);
+ babl_model ("RGBA"),
+ babl_type ("u8"),
+ babl_component ("R"),
+ babl_component ("G"),
+ babl_component ("B"),
+ babl_component ("A"),
+ NULL);
Babl *rgbAF = babl_format_new (
- babl_model ("RaGaBaA"),
- babl_type ("float"),
- babl_component ("Ra"),
- babl_component ("Ga"),
- babl_component ("Ba"),
- babl_component ("A"),
- NULL);
+ babl_model ("RaGaBaA"),
+ babl_type ("float"),
+ babl_component ("Ra"),
+ babl_component ("Ga"),
+ babl_component ("Ba"),
+ babl_component ("A"),
+ NULL);
Babl *rgbA16 = babl_format_new (
- babl_model ("RaGaBaA"),
- babl_type ("u16"),
- babl_component ("Ra"),
- babl_component ("Ga"),
- babl_component ("Ba"),
- babl_component ("A"),
- NULL);
+ babl_model ("RaGaBaA"),
+ babl_type ("u16"),
+ babl_component ("Ra"),
+ babl_component ("Ga"),
+ babl_component ("Ba"),
+ babl_component ("A"),
+ NULL);
Babl *rgbA8 = babl_format_new (
- babl_model ("RaGaBaA"),
- babl_type ("u8"),
- babl_component ("Ra"),
- babl_component ("Ga"),
- babl_component ("Ba"),
- babl_component ("A"),
- NULL);
+ babl_model ("RaGaBaA"),
+ babl_type ("u8"),
+ babl_component ("Ra"),
+ babl_component ("Ga"),
+ babl_component ("Ba"),
+ babl_component ("A"),
+ NULL);
Babl *rgbF = babl_format_new (
- babl_model ("RGB"),
- babl_type ("float"),
- babl_component ("R"),
- babl_component ("G"),
- babl_component ("B"),
- NULL);
+ babl_model ("RGB"),
+ babl_type ("float"),
+ babl_component ("R"),
+ babl_component ("G"),
+ babl_component ("B"),
+ NULL);
Babl *rgb16 = babl_format_new (
- babl_model ("RGB"),
- babl_type ("u16"),
- babl_component ("R"),
- babl_component ("G"),
- babl_component ("B"),
- NULL);
+ babl_model ("RGB"),
+ babl_type ("u16"),
+ babl_component ("R"),
+ babl_component ("G"),
+ babl_component ("B"),
+ NULL);
Babl *rgb8 = babl_format_new (
- babl_model ("RGB"),
- babl_type ("u8"),
- babl_component ("R"),
- babl_component ("G"),
- babl_component ("B"),
- NULL);
+ babl_model ("RGB"),
+ babl_type ("u8"),
+ babl_component ("R"),
+ babl_component ("G"),
+ babl_component ("B"),
+ NULL);
Babl *gaF = babl_format_new (
- babl_model ("YA"),
- babl_type ("float"),
- babl_component ("Y"),
- babl_component ("A"),
- NULL);
+ babl_model ("YA"),
+ babl_type ("float"),
+ babl_component ("Y"),
+ babl_component ("A"),
+ NULL);
Babl *gAF = babl_format_new (
- babl_model ("YaA"),
- babl_type ("float"),
- babl_component ("Ya"),
- babl_component ("A"),
- NULL);
+ babl_model ("YaA"),
+ babl_type ("float"),
+ babl_component ("Ya"),
+ babl_component ("A"),
+ NULL);
Babl *gF = babl_format_new (
- babl_model ("Y"),
- babl_type ("float"),
- babl_component ("Y"),
- NULL);
+ babl_model ("Y"),
+ babl_type ("float"),
+ babl_component ("Y"),
+ NULL);
Babl *ga16 = babl_format_new (
- babl_model ("YA"),
- babl_type ("u16"),
- babl_component ("Y"),
- babl_component ("A"),
- NULL);
+ babl_model ("YA"),
+ babl_type ("u16"),
+ babl_component ("Y"),
+ babl_component ("A"),
+ NULL);
Babl *gA16 = babl_format_new (
- babl_model ("YaA"),
- babl_type ("u16"),
- babl_component ("Ya"),
- babl_component ("A"),
- NULL);
+ babl_model ("YaA"),
+ babl_type ("u16"),
+ babl_component ("Ya"),
+ babl_component ("A"),
+ NULL);
Babl *g16 = babl_format_new (
- babl_model ("Y"),
- babl_type ("u16"),
- babl_component ("Y"),
- NULL);
+ babl_model ("Y"),
+ babl_type ("u16"),
+ babl_component ("Y"),
+ NULL);
Babl *ga8 = babl_format_new (
- babl_model ("YA"),
- babl_type ("u8"),
- babl_component ("Y"),
- babl_component ("A"),
- NULL);
+ babl_model ("YA"),
+ babl_type ("u8"),
+ babl_component ("Y"),
+ babl_component ("A"),
+ NULL);
Babl *gA8 = babl_format_new (
- babl_model ("YaA"),
- babl_type ("u8"),
- babl_component ("Ya"),
- babl_component ("A"),
- NULL);
+ babl_model ("YaA"),
+ babl_type ("u8"),
+ babl_component ("Ya"),
+ babl_component ("A"),
+ NULL);
Babl *g8 = babl_format_new (
- babl_model ("Y"),
- babl_type ("u8"),
- babl_component ("Y"),
- NULL);
+ babl_model ("Y"),
+ babl_type ("u8"),
+ babl_component ("Y"),
+ NULL);
Babl *yuv8 = babl_format_new (
- "name", "Y'CbCr u8",
- babl_model ("Y'CbCr"),
- babl_type ("u8-luma"),
- babl_component ("Y'"),
- babl_type ("u8-chroma"),
- babl_component ("Cb"),
- babl_component ("Cr"),
- NULL);
+ "name", "Y'CbCr u8",
+ babl_model ("Y'CbCr"),
+ babl_type ("u8-luma"),
+ babl_component ("Y'"),
+ babl_type ("u8-chroma"),
+ babl_component ("Cb"),
+ babl_component ("Cr"),
+ NULL);
Babl *yuvF = babl_format_new (
- babl_model ("Y'CbCr"),
- babl_type ("float"),
- babl_component ("Y'"),
- babl_type ("float"),
- babl_component ("Cb"),
- babl_component ("Cr"),
- NULL);
+ babl_model ("Y'CbCr"),
+ babl_type ("float"),
+ babl_component ("Y'"),
+ babl_type ("float"),
+ babl_component ("Cb"),
+ babl_component ("Cr"),
+ NULL);
Babl *yuvaF = babl_format_new (
- babl_model ("Y'CbCrA"),
- babl_type ("float"),
- babl_component ("Y'"),
- babl_type ("float"),
- babl_component ("Cb"),
- babl_component ("Cr"),
- babl_component ("A"),
- NULL);
-
-#define o(src,dst) \
- babl_conversion_new (src, dst, "linear", conv_##src##_##dst, NULL)
+ babl_model ("Y'CbCrA"),
+ babl_type ("float"),
+ babl_component ("Y'"),
+ babl_type ("float"),
+ babl_component ("Cb"),
+ babl_component ("Cr"),
+ babl_component ("A"),
+ NULL);
+
+#define o(src, dst) \
+ babl_conversion_new (src, dst, "linear", conv_ ## src ## _ ## dst, NULL)
o (rgbaF, rgbaD);
o (rgbaD, rgbaF);
#include "babl.h"
-#define INLINE inline
+#define INLINE inline
#include <math.h>
#include <stdio.h>
*
* due to ability to be able to relicence gggl under a different
* licence than GPL, I avoided the temptation to look at the
- * source files in the same location, in case I was going to
+ * source files in the same location, in case I was going to
* need this piece of code for projects where GPL compatibility
* was a must.
*
/* lookup tables used in conversion */
-static float table_8_F[1 << 8];
-static float table_16_F[1 << 16];
-static unsigned char table_F_8[1 << 16];
+static float table_8_F[1 << 8];
+static float table_16_F[1 << 16];
+static unsigned char table_F_8[1 << 16];
static unsigned short table_F_16[1 << 16];
/* fill tables for conversion from integer to float */
{
- int i;
+ int i;
for (i = 0; i < 1 << 8; i++)
{
table_8_F[i] = (i * 1.0) / 255.0;
{
union
{
- float f;
+ float f;
unsigned short s[2];
} u;
u.f = 0.0;
for (u.s[1] = 0; u.s[1] < 65535; u.s[1] += 1)
{
- unsigned char c;
+ unsigned char c;
unsigned short s;
if (u.f <= 0.0)
/ if (! ((*hi)%9))
/ fprintf (stderr, "\n"); */
- table_F_8[u.s[1]] = c;
+ table_F_8[u.s[1]] = c;
table_F_16[u.s[1]] = s;
}
}
/* fix tables to ensure 1:1 conversions back and forth */
if (0)
{ /*FIXME: probably not the right way to do it,.. must sit down and scribble on paper */
- int i;
+ int i;
for (i = 0; i < 256; i++)
{
- float f = table_8_F[i];
- unsigned short *hi = ((unsigned short *)(void*) &f);
- unsigned short *lo = ((unsigned short *)(void*) &f);
- *lo = 0;
+ float f = table_8_F[i];
+ unsigned short *hi = ((unsigned short *) (void *) &f);
+ unsigned short *lo = ((unsigned short *) (void *) &f);
+ *lo = 0;
table_F_8[(*hi)] = i;
}
}
{
union
{
- float f;
+ float f;
unsigned short s[2];
} u;
u.f = f;
static INLINE long
conv_F_8 (unsigned char *src, unsigned char *dst, long samples)
{
- long n=samples;
+ long n = samples;
+
if (!table_inited)
table_init ();
while (n--)
{
register float f = (*(float *) src);
*(unsigned char *) dst = table_F_8[gggl_float_to_index16 (f)];
- dst += 1;
- src += 4;
+ dst += 1;
+ src += 4;
}
return samples;
}
static INLINE long
conv_F_16 (unsigned char *src, unsigned char *dst, long samples)
{
- long n=samples;
+ long n = samples;
+
if (!table_inited)
table_init ();
while (n--)
{
register float f = (*(float *) src);
*(unsigned short *) dst = table_F_16[gggl_float_to_index16 (f)];
- dst += 2;
- src += 4;
+ dst += 2;
+ src += 4;
}
return samples;
}
static INLINE long
conv_8_F (unsigned char *src, unsigned char *dst, long samples)
{
- long n=samples;
+ long n = samples;
+
if (!table_inited)
table_init ();
while (n--)
{
(*(float *) dst) = table_8_F[*(unsigned char *) src];
- dst += 4;
- src += 1;
+ dst += 4;
+ src += 1;
}
return samples;
}
static INLINE long
conv_16_F (unsigned char *src, unsigned char *dst, long samples)
{
- long n=samples;
+ long n = samples;
+
if (!table_inited)
table_init ();
while (n--)
{
(*(float *) dst) = table_16_F[*(unsigned short *) src];
- dst += 4;
- src += 2;
+ dst += 4;
+ src += 2;
}
return samples;
}
static INLINE long
conv_F_8 (unsigned char *src, unsigned char *dst, long samples)
{
- long n=samples;
+ long n = samples;
+
while (n--)
{
- float f = ((*(float *) src));
+ float f = ((*(float *) src));
int uval = rint (f * 255.0);
if (uval < 0) uval = 0;
static INLINE long
conv_F_16 (unsigned char *src, unsigned char *dst, long samples)
{
- long n=samples;
+ long n = samples;
+
while (n--)
{
- float f = ((*(float *) src));
+ float f = ((*(float *) src));
if (f < 0.0)
{
*(unsigned short *) dst = 0;
static INLINE long
conv_8_F (unsigned char *src, unsigned char *dst, long samples)
{
- long n=samples;
+ long n = samples;
+
while (n--)
{
(*(float *) dst) = ((*(unsigned char *) src) / 255.0);
- dst += 4;
- src += 1;
+ dst += 4;
+ src += 1;
}
return samples;
}
static INLINE long
conv_16_F (unsigned char *src, unsigned char *dst, long samples)
{
- long n=samples;
+ long n = samples;
+
while (n--)
{
(*(float *) dst) = *(unsigned short *) src / 65535.0;
- dst += 4;
- src += 2;
+ dst += 4;
+ src += 2;
}
return samples;
}
static INLINE long
conv_F_D (unsigned char *src, unsigned char *dst, long samples)
{
- long n=samples;
+ long n = samples;
+
while (n--)
{
*(double *) dst = ((*(float *) src));
- dst += 8;
- src += 4;
+ dst += 8;
+ src += 4;
}
return samples;
}
static INLINE long
conv_D_F (unsigned char *src, unsigned char *dst, long samples)
{
- long n=samples;
+ long n = samples;
+
while (n--)
{
*(float *) dst = ((*(double *) src));
- dst += 4;
- src += 8;
+ dst += 4;
+ src += 8;
}
return samples;
}
static INLINE long
conv_16_8 (unsigned char *src, unsigned char *dst, long samples)
{
- long n=samples;
+ long n = samples;
+
while (n--)
{
(*(unsigned char *) dst) = (*(unsigned short *) src) >> 8;
- dst += 1;
- src += 2;
+ dst += 1;
+ src += 2;
}
return samples;
}
static INLINE long
conv_8_16 (unsigned char *src, unsigned char *dst, long samples)
{
- long n=samples;
+ long n = samples;
+
while (n--)
{
(*(unsigned short *) dst) = (*(unsigned char *) src) << 8;
- dst += 2;
- src += 1;
+ dst += 2;
+ src += 1;
}
return samples;
}
static INLINE long
conv_rgbaF_rgb8 (unsigned char *src, unsigned char *dst, long samples)
{
- long n=samples;
+ long n = samples;
+
while (n--)
- {
+ {
register float f = (*(float *) src);
*(unsigned char *) dst = table_F_8[gggl_float_to_index16 (f)];
- src += 4;
- dst += 1;
+ src += 4;
+ dst += 1;
- f = (*(float *) src);
+ f = (*(float *) src);
*(unsigned char *) dst = table_F_8[gggl_float_to_index16 (f)];
- src += 4;
- dst += 1;
+ src += 4;
+ dst += 1;
- f = (*(float *) src);
+ f = (*(float *) src);
*(unsigned char *) dst = table_F_8[gggl_float_to_index16 (f)];
- src += 4;
- dst += 1;
+ src += 4;
+ dst += 1;
src += 4;
-
- }
+ }
return samples;
}
return samples;
}
-#define conv_rgbaF_rgbP8 conv_rgbaF_rgba8
+#define conv_rgbaF_rgbP8 conv_rgbaF_rgba8
static INLINE long
conv_rgbF_rgb8 (unsigned char *src, unsigned char *dst, long samples)
return samples;
}
-#define conv_rgbAF_rgbA8 conv_rgbaF_rgba8
-#define conv_gF_g8 conv_F_8
-#define conv_gAF_gA8 conv_gaF_ga8
+#define conv_rgbAF_rgbA8 conv_rgbaF_rgba8
+#define conv_gF_g8 conv_F_8
+#define conv_gAF_gA8 conv_gaF_ga8
static INLINE long
conv_rgbaF_rgba16 (unsigned char *src, unsigned char *dst, long samples)
return samples;
}
-#define conv_rgbAF_rgbA16 conv_rgbaF_rgba16
-#define conv_gF_g16 conv_F_16
-#define conv_gAF_gA16 conv_gaF_ga16
+#define conv_rgbAF_rgbA16 conv_rgbaF_rgba16
+#define conv_gF_g16 conv_F_16
+#define conv_gAF_gA16 conv_gaF_ga16
static INLINE long
conv_rgba8_rgbaF (unsigned char *src, unsigned char *dst, long samples)
return conv_8_F (src, dst, samples * 2) / 2;
}
-#define conv_rgbA8_rgbAF conv_rgba8_rgbaF
-#define conv_gA8_gAF conv_ga8_gaF
-#define conv_g8_gF conv_8_F
+#define conv_rgbA8_rgbAF conv_rgba8_rgbaF
+#define conv_gA8_gAF conv_ga8_gaF
+#define conv_g8_gF conv_8_F
static INLINE long
conv_rgbaF_rgbaD (unsigned char *src, unsigned char *dst, long samples)
return samples;
}
-#define conv_rgbA16_rgbAF conv_rgba16_rgbaF
-#define conv_gA16_gAF conv_ga16_gaF
-#define conv_g16_gF conv_16_F
+#define conv_rgbA16_rgbAF conv_rgba16_rgbaF
+#define conv_gA16_gAF conv_ga16_gaF
+#define conv_g16_gF conv_16_F
static INLINE long
conv_rgba16_rgba8 (unsigned char *src, unsigned char *dst, long samples)
return samples;
}
-#define conv_rgbA16_rgbA8 conv_rgba16_rgba8
-#define conv_gA16_gA8 conv_ga16_ga8
-#define conv_g16_g8 conv_16_8
+#define conv_rgbA16_rgbA8 conv_rgba16_rgba8
+#define conv_gA16_gA8 conv_ga16_ga8
+#define conv_g16_g8 conv_16_8
static INLINE long
conv_rgba8_rgba16 (unsigned char *src, unsigned char *dst, long samples)
return samples;
}
-#define conv_rgbA8_rgbA16 conv_rgba8_rgba16
-#define conv_gA8_gA16 conv_ga8_ga16
-#define conv_g8_g16 conv_8_16
+#define conv_rgbA8_rgbA16 conv_rgba8_rgba16
+#define conv_gA8_gA16 conv_ga8_ga16
+#define conv_g8_g16 conv_8_16
/* alpha conversions */
static INLINE long
conv_gaF_gAF (unsigned char *src, unsigned char *dst, long samples)
{
- long n=samples;
+ long n = samples;
+
while (n--)
{
- float alpha = (*(float *) (src + 4));
+ float alpha = (*(float *) (src + 4));
*(float *) dst = ((*(float *) src) * alpha);
- dst += 4;
- src += 4;
+ dst += 4;
+ src += 4;
*(float *) dst = alpha;
- dst += 4;
- src += 4;
+ dst += 4;
+ src += 4;
}
return samples;
}
static INLINE long
conv_gAF_gaF (unsigned char *src, unsigned char *dst, long samples)
{
- long n=samples;
+ long n = samples;
+
while (n--)
{
- float alpha = (*(float *) (src + 4));
+ float alpha = (*(float *) (src + 4));
*(float *) dst = ((*(float *) src) / alpha);
- dst += 4;
- src += 4;
+ dst += 4;
+ src += 4;
*(float *) dst = alpha;
- dst += 4;
- src += 4;
+ dst += 4;
+ src += 4;
}
return samples;
}
static INLINE long
conv_rgbAF_rgbaF (unsigned char *src, unsigned char *dst, long samples)
{
- long n=samples;
+ long n = samples;
+
while (n--)
{
- float alpha = (((float *) src)[3]);
- int c;
+ float alpha = (((float *) src)[3]);
+ int c;
if (alpha >= 1.0)
{
for (c = 0; c < 3; c++)
{
*(float *) dst = *(float *) src;
- dst += 4;
- src += 4;
+ dst += 4;
+ src += 4;
}
}
else if (alpha <= 0.0)
for (c = 0; c < 3; c++)
{
*(float *) dst = 0;
- dst += 4;
- src += 4;
+ dst += 4;
+ src += 4;
}
}
else
for (c = 0; c < 3; c++)
{
*(float *) dst = ((*(float *) src) / alpha);
- dst += 4;
- src += 4;
+ dst += 4;
+ src += 4;
}
}
*(float *) dst = alpha;
- dst += 4;
- src += 4;
+ dst += 4;
+ src += 4;
}
return samples;
}
static INLINE long
conv_rgbAF_rgbF (unsigned char *src, unsigned char *dst, long samples)
{
- long n=samples;
+ long n = samples;
+
while (n--)
{
- float alpha = (((float *) src)[3]);
+ float alpha = (((float *) src)[3]);
if (alpha >= 1.0)
{
- register int c;
+ register int c;
for (c = 0; c < 3; c++)
{
*(float *) dst = *(float *) src;
- dst += 4;
- src += 4;
+ dst += 4;
+ src += 4;
}
}
else if (alpha <= 0.0)
{
- register int c;
+ register int c;
for (c = 0; c < 3; c++)
{
*(float *) dst = 0;
- dst += 4;
- src += 4;
+ dst += 4;
+ src += 4;
}
}
else
{
- register int c;
+ register int c;
for (c = 0; c < 3; c++)
{
*(float *) dst = ((*(float *) src) / alpha);
- dst += 4;
- src += 4;
+ dst += 4;
+ src += 4;
}
}
src += 4;
static INLINE long
conv_rgbaF_rgbAF (unsigned char *src, unsigned char *dst, long samples)
{
- long n=samples;
+ long n = samples;
+
while (n--)
{
- float alpha = (((float *) src)[3]);
- int c;
+ float alpha = (((float *) src)[3]);
+ int c;
if (alpha >= 1.0)
{
for (c = 0; c < 3; c++)
{
*(float *) dst = *(float *) src;
- dst += 4;
- src += 4;
+ dst += 4;
+ src += 4;
}
}
else if (alpha <= 0.0)
for (c = 0; c < 3; c++)
{
*(float *) dst = 0;
- dst += 4;
- src += 4;
+ dst += 4;
+ src += 4;
}
}
else
for (c = 0; c < 3; c++)
{
*(float *) dst = ((*(float *) src) * alpha);
- dst += 4;
- src += 4;
+ dst += 4;
+ src += 4;
}
}
*(float *) dst = alpha;
- dst += 4;
- src += 4;
+ dst += 4;
+ src += 4;
}
return samples;
}
static INLINE long
conv_rgbaF_rgbF (unsigned char *src, unsigned char *dst, long samples)
{
- long n=samples;
+ long n = samples;
+
while (n--)
{
*(float *) dst = (*(float *) src);
- dst += 4;
- src += 4;
+ dst += 4;
+ src += 4;
*(float *) dst = (*(float *) src);
- dst += 4;
- src += 4;
+ dst += 4;
+ src += 4;
*(float *) dst = (*(float *) src);
- dst += 4;
- src += 4;
- src += 4;
+ dst += 4;
+ src += 4;
+ src += 4;
}
return samples;
}
static INLINE long
conv_rgbF_rgbaF (unsigned char *src, unsigned char *dst, long samples)
{
- long n=samples;
+ long n = samples;
+
while (n--)
{
*(float *) dst = (*(float *) src);
- src += 4;
- dst += 4;
+ src += 4;
+ dst += 4;
*(float *) dst = (*(float *) src);
- src += 4;
- dst += 4;
+ src += 4;
+ dst += 4;
*(float *) dst = (*(float *) src);
- src += 4;
- dst += 4;
+ src += 4;
+ dst += 4;
*(float *) dst = 1.0;
- dst += 4;
+ dst += 4;
}
return samples;
}
static INLINE long
conv_gaF_gF (unsigned char *src, unsigned char *dst, long samples)
{
- long n=samples;
+ long n = samples;
+
while (n--)
{
*(int *) dst = (*(int *) src);
- dst += 4;
- src += 4;
- src += 4;
+ dst += 4;
+ src += 4;
+ src += 4;
}
return samples;
}
static INLINE long
conv_gF_gaF (unsigned char *src, unsigned char *dst, long samples)
{
- long n=samples;
+ long n = samples;
+
while (n--)
{
*(float *) dst = (*(float *) src);
- dst += 4;
- src += 4;
+ dst += 4;
+ src += 4;
*(float *) dst = 1.0;
- dst += 4;
+ dst += 4;
}
return samples;
}
-#define conv_gAF_gF conv_gaF_gF
-#define conv_gF_gAF conv_gF_gaF
+#define conv_gAF_gF conv_gaF_gF
+#define conv_gF_gAF conv_gF_gaF
-#define conv_rgbAF_rgbF conv_rgbaF_rgbF
-#define conv_rgbF_rgbAF conv_rgbF_rgbaF
+#define conv_rgbAF_rgbF conv_rgbaF_rgbF
+#define conv_rgbF_rgbAF conv_rgbF_rgbaF
/* colorchannel dropping and adding */
static INLINE long
conv_gF_rgbF (unsigned char *src, unsigned char *dst, long samples)
{
- long n=samples;
+ long n = samples;
+
while (n--)
{
- int c;
+ int c;
for (c = 0; c < 3; c++)
{
(*(float *) dst) = (*(float *) src);
- dst += 4;
+ dst += 4;
}
src += 4;
}
static INLINE long
conv_rgbF_gF (unsigned char *src, unsigned char *dst, long samples)
{
- long n=samples;
+ long n = samples;
+
while (n--)
{
- int c;
- float sum = 0;
+ int c;
+ float sum = 0;
for (c = 0; c < 3; c++)
{
sum += (*(float *) src);
src += 4;
}
- sum /= 3.0;
+ sum /= 3.0;
(*(float *) dst) = sum;
- dst += 4;
+ dst += 4;
}
return samples;
}
static INLINE long
conv_gaF_rgbaF (unsigned char *src, unsigned char *dst, long samples)
{
- long n=samples;
+ long n = samples;
+
while (n--)
{
- int c;
+ int c;
for (c = 0; c < 3; c++)
{
(*(int *) dst) = (*(int *) src);
- dst += 4;
+ dst += 4;
}
- src += 4;
+ src += 4;
(*(int *) dst) = (*(int *) src);
- dst += 4;
- src += 4;
+ dst += 4;
+ src += 4;
}
return samples;
}
static INLINE long
conv_rgbaF_gaF (unsigned char *src, unsigned char *dst, long samples)
{
- long n=samples;
+ long n = samples;
+
while (n--)
{
- float gray = 0;
+ float gray = 0;
- gray += (*(float *) src) * 0.212671;
- src += 4;
- gray += (*(float *) src) * 0.715160;
- src += 4;
- gray += (*(float *) src) * 0.072169;
- src += 4;
+ gray += (*(float *) src) * 0.212671;
+ src += 4;
+ gray += (*(float *) src) * 0.715160;
+ src += 4;
+ gray += (*(float *) src) * 0.072169;
+ src += 4;
(*(float *) dst) = gray;
- dst += 4;
- (*(int *) dst) = (*(int *) src);
- dst += 4;
- src += 4;
-
+ dst += 4;
+ (*(int *) dst) = (*(int *) src);
+ dst += 4;
+ src += 4;
}
return samples;
}
-#define conv_gAF_rgbAF conv_gaF_rgbaF
-#define conv_rgbAF_gAF conv_rgbaF_gaF
+#define conv_gAF_rgbAF conv_gaF_rgbaF
+#define conv_rgbAF_gAF conv_rgbaF_gaF
/* other conversions coded for some optimisation reason or sumthin */
static INLINE long
conv_rgbA8_rgbaF (unsigned char *src, unsigned char *dst, long samples)
{
- long n=samples;
+ long n = samples;
+
while (n--)
{
- float alpha = (*(unsigned char *) src + (3)) / 255.0;
- int c;
+ float alpha = (*(unsigned char *) src + (3)) / 255.0;
+ int c;
for (c = 0; c < 3; c++)
{
(*(float *) dst) = (*(unsigned char *) src / 255.0) / alpha;
- dst += 4;
- src += 1;
+ dst += 4;
+ src += 1;
}
*(float *) dst = alpha;
- dst += 4;
- src += 1;
+ dst += 4;
+ src += 1;
}
return samples;
}
static INLINE long
conv_rgbaF_rgbA8 (unsigned char *src, unsigned char *dst, long samples)
{
- long n=samples;
+ long n = samples;
+
while (n--)
{
- float alpha = (*(float *) (src + (4 * 3)));
- int c;
+ float alpha = (*(float *) (src + (4 * 3)));
+ int c;
for (c = 0; c < 3; c++)
{
*(unsigned char *) dst = ((*(float *) src) * alpha) * 255.0;
- dst += 1;
- src += 4;
+ dst += 1;
+ src += 4;
}
*(unsigned char *) dst = alpha * 255.0;
dst++;
static INLINE long
conv_rgbaF_rgbA16 (unsigned char *src, unsigned char *dst, long samples)
{
- long n=samples;
+ long n = samples;
+
while (n--)
{
- float alpha = (*(float *) src + (4 * 3));
- int c;
+ float alpha = (*(float *) src + (4 * 3));
+ int c;
for (c = 0; c < 3; c++)
{
*(unsigned short *) dst = ((*(float *) src) * alpha) * 65535.0;
- dst += 2;
- src += 4;
+ dst += 2;
+ src += 4;
}
*(unsigned short *) dst = alpha * 65535.0;
- dst += 2;
- src += 4;
+ dst += 2;
+ src += 4;
}
return samples;
}
static INLINE long
conv_rgbaF_rgb8 (unsigned char *src, unsigned char *dst, long samples)
{
- long n=samples;
+ long n = samples;
+
while (n--)
{
- int c;
+ int c;
for (c = 0; c < 3; c++)
{
- int val=rint ((*(float *) src) * 255.0);
- if (val<0)
+ int val = rint ((*(float *) src) * 255.0);
+ if (val < 0)
*(unsigned char *) dst = 0;
- else if (val>255)
+ else if (val > 255)
*(unsigned char *) dst = 255;
else
*(unsigned char *) dst = val;
static INLINE long
conv_rgbaF_g8 (unsigned char *src, unsigned char *dst, long samples)
{
- long n=samples;
+ long n = samples;
+
while (n--)
{
- int c;
- float sum = 0;
+ int c;
+ float sum = 0;
for (c = 0; c < 3; c++)
{
static INLINE long
conv_rgbaF_rgb16 (unsigned char *src, unsigned char *dst, long samples)
{
- long n=samples;
+ long n = samples;
+
while (n--)
{
- int c;
+ int c;
for (c = 0; c < 3; c++)
{
*(unsigned short *) dst = (*(float *) src) * 65535.0;
- dst += 2;
- src += 4;
+ dst += 2;
+ src += 4;
}
src += 4;
}
static INLINE long
conv_rgbP8_rgbaF (unsigned char *src, unsigned char *dst, long samples)
{
- long n=samples;
+ long n = samples;
+
while (n--)
{
- int c;
+ int c;
for (c = 0; c < 3; c++)
{
(*(float *) dst) = *(unsigned char *) src / 255.0;
- dst += 4;
- src += 1;
+ dst += 4;
+ src += 1;
}
(*(float *) dst) = 1.0;
- dst += 4;
- src += 1;
+ dst += 4;
+ src += 1;
}
return samples;
}
static INLINE long
conv_rgbA16_rgbaF (unsigned char *src, unsigned char *dst, long samples)
{
- long n=samples;
+ long n = samples;
+
while (n--)
{
- float alpha = (((unsigned short *) src)[3]) / 65535.0;
- int c;
+ float alpha = (((unsigned short *) src)[3]) / 65535.0;
+ int c;
for (c = 0; c < 3; c++)
{
(*(float *) dst) = (*(unsigned short *) src / 65535.0) / alpha;
- dst += 4;
- src += 2;
+ dst += 4;
+ src += 2;
}
*(float *) dst = alpha;
- dst += 4;
- src += 2;
+ dst += 4;
+ src += 2;
}
return samples;
}
/*
-static INLINE long
-conv_rgb8_rgbaF (unsigned char *src,
+ static INLINE long
+ conv_rgb8_rgbaF (unsigned char *src,
unsigned char *dst,
int samples)
-{
+ {
long n=samples;
while (n--) {
int c;
-
+
for (c = 0; c < 3; c++) {
(*(float *) dst) = *(unsigned char *) src / 255.0;
dst += 4;
(*(float *) dst) = 1.0;
dst += 4;
}
- return samples;
-}
-
-static INLINE long
-conv_g8_rgbaF (unsigned char *src,
+ return samples;
+ }
+
+ static INLINE long
+ conv_g8_rgbaF (unsigned char *src,
unsigned char *dst,
int samples)
-{
+ {
long n=samples;
while (n--) {
int c;
(*(float *) dst) = 1.0;
dst += 4;
}
- return samples;
-}
+ return samples;
+ }
-static INLINE long
-conv_rgb16_rgbaF (unsigned char *src,
+ static INLINE long
+ conv_rgb16_rgbaF (unsigned char *src,
unsigned char *dst,
int samples)
-{
+ {
long n=samples;
while (n--) {
int c;
for (c = 0; c < 3; c++) {
- *(float *) dst = (*(unsigned short *) src) / 65535.0;
+ *(float *) dst = (*(unsigned short *) src) / 65535.0;
src += 2;
dst += 4;
}
- *(float *) dst = 1.0;
+ *(float *) dst = 1.0;
src += 2;
dst += 4;
}
- return samples;
-}
+ return samples;
+ }
-static INLINE long
-conv_gF_rgbaF (unsigned char *src,
+ static INLINE long
+ conv_gF_rgbaF (unsigned char *src,
unsigned char *dst,
int samples)
-{
+ {
long n=samples;
while (n--) {
(*(float *) dst) = (*(float *) src);
src += 4;
}
- return samples;
-}
-*/
+ return samples;
+ }
+ */
static INLINE long
conv_rgba8_rgbA8 (unsigned char *src, unsigned char *dst, long samples)
{
- long n=samples;
+ long n = samples;
+
while (n--)
{
if (src[3] == 255)
static INLINE long
conv_rgbA8_rgba8 (unsigned char *src, unsigned char *dst, long samples)
{
- long n=samples;
+ long n = samples;
+
while (n--)
{
if (src[3] == 255)
{
*(unsigned int *) dst = *(unsigned int *) src;
- dst += 4;
+ dst += 4;
}
else if (src[3] == 0)
{
*(unsigned int *) dst = 0;
- dst += 4;
+ dst += 4;
}
else
{
static INLINE long
conv_argb8_rgba8 (unsigned char *src, unsigned char *dst, long samples)
{
- long n=samples;
+ long n = samples;
+
while (n--)
{
dst[0] = src[2];
dst[1] = src[1];
dst[2] = src[0];
dst[3] = src[3];
- src += 4;
- dst += 4;
+ src += 4;
+ dst += 4;
}
return samples;
}
static INLINE long
conv_rgba8_argb8 (unsigned char *src, unsigned char *dst, long samples)
{
- long n=samples;
+ long n = samples;
+
while (n--)
{
dst[0] = src[3];
dst[1] = src[0];
dst[2] = src[1];
dst[3] = src[2];
- src += 4;
- dst += 4;
+ src += 4;
+ dst += 4;
}
return samples;
}
static INLINE long
conv_Argb8_rgbA8 (unsigned char *src, unsigned char *dst, long samples)
{
- long n=samples;
+ long n = samples;
+
while (n--)
{
dst[0] = src[2];
dst[1] = src[1];
dst[2] = src[0];
dst[3] = src[3];
- src += 4;
- dst += 4;
+ src += 4;
+ dst += 4;
}
return samples;
}
static INLINE long
conv_rgbA8_Argb8 (unsigned char *src, unsigned char *dst, long samples)
{
- long n=samples;
+ long n = samples;
+
while (n--)
{
dst[0] = src[2];
dst[1] = src[1];
dst[2] = src[0];
dst[3] = src[3];
- src += 4;
- dst += 4;
+ src += 4;
+ dst += 4;
}
return samples;
}
static INLINE long
conv_Prgb8_rgbP8 (unsigned char *src, unsigned char *dst, long samples)
{
- long n=samples;
+ long n = samples;
+
while (n--)
{
dst[0] = src[2];
dst[1] = src[1];
dst[2] = src[0];
dst[3] = 255;
- src += 4;
- dst += 4;
+ src += 4;
+ dst += 4;
}
return samples;
}
static INLINE long
conv_rgbP8_Prgb8 (unsigned char *src, unsigned char *dst, long samples)
{
- long n=samples;
+ long n = samples;
+
while (n--)
{
dst[0] = src[2];
dst[1] = src[1];
dst[2] = src[0];
dst[3] = 255;
- src += 4;
- dst += 4;
+ src += 4;
+ dst += 4;
}
return samples;
}
static INLINE long
conv_Prgb8_rgb8 (unsigned char *src, unsigned char *dst, long samples)
{
- long n=samples;
+ long n = samples;
+
while (n--)
{
dst[0] = src[2];
static INLINE long
conv_rgb8_Prgb8 (unsigned char *src, unsigned char *dst, long samples)
{
- long n=samples;
+ long n = samples;
+
while (n--)
{
dst[0] = src[2]; /* blue */
dst[1] = src[1]; /* green */
dst[2] = src[0]; /* red */
dst[3] = 255;
- src += 3;
- dst += 4;
+ src += 3;
+ dst += 4;
}
return samples;
}
static INLINE long
conv_rgbA16_rgba16 (unsigned char *src, unsigned char *dst, long samples)
{
- long n=samples;
+ long n = samples;
+
while (n--)
{
if (src[3])
(((unsigned short *) src)[2] * 65535) / src[3];
}
((unsigned short *) dst)[3] = ((unsigned short *) src)[3];
- dst += 8;
- src += 8;
+ dst += 8;
+ src += 8;
}
return samples;
}
static INLINE long
conv_rgb8_rgbP8 (unsigned char *src, unsigned char *dst, long samples)
{
- long n=samples;
+ long n = samples;
+
while (n--)
{
dst[0] = src[0];
dst[1] = src[1];
dst[2] = src[2];
- src += 3;
- dst += 4;
+ src += 3;
+ dst += 4;
}
return samples;
}
static INLINE long
conv_rgb8_rgba8 (unsigned char *src, unsigned char *dst, long samples)
{
- long n=samples;
+ long n = samples;
+
while (n--)
{
/**(unsigned int *) dst = *(unsigned int *) src;
- dst[3] = 255;*/
+ dst[3] = 255;*/
dst[0] = src[0];
dst[1] = src[1];
dst[2] = src[2];
dst[3] = 255;
- src += 3;
- dst += 4;
+ src += 3;
+ dst += 4;
}
return samples;
}
-#define conv_rgb8_rgbA8 conv_rgb8_rgba8
+#define conv_rgb8_rgbA8 conv_rgb8_rgba8
static INLINE long
conv_rgbP8_rgba8 (unsigned char *src, unsigned char *dst, long samples)
{
- long n=samples;
+ long n = samples;
+
while (n--)
{
*(unsigned int *) dst = *(unsigned int *) src;
- dst[3] = 255;
- src += 4;
- dst += 4;
+ dst[3] = 255;
+ src += 4;
+ dst += 4;
}
return samples;
}
-#define conv_rgbP8_rgbA8 conv_rgbP8_rgba8
+#define conv_rgbP8_rgbA8 conv_rgbP8_rgba8
static INLINE long
conv_rgba8_rgbP8 (unsigned char *src, unsigned char *dst, long samples)
return samples;
}
-#define conv_rgbA8_rgbP8 conv_rgba8_rgbP8
+#define conv_rgbA8_rgbP8 conv_rgba8_rgbP8
static INLINE long
conv_rgbP8_rgb8 (unsigned char *src, unsigned char *dst, long samples)
{
- long n=samples;
+ long n = samples;
+
while (n--)
{
dst[0] = src[0];
dst[1] = src[1];
dst[2] = src[2];
- src += 4;
- dst += 3;
+ src += 4;
+ dst += 3;
}
return samples;
}
static INLINE long
conv_rgba8_rgb8 (unsigned char *src, unsigned char *dst, long samples)
{
- long n=samples;
+ long n = samples;
+
while (n--)
{
dst[0] = src[0];
dst[1] = src[1];
dst[2] = src[2];
- src += 4;
- dst += 3;
+ src += 4;
+ dst += 3;
}
return samples;
}
static INLINE long
conv_rgbA8_rgb8 (unsigned char *src, unsigned char *dst, long samples)
{
- long n=samples;
+ long n = samples;
+
while (n--)
{
int alpha = src[3];
}
#ifndef byteclamp
-#define byteclamp(j) do{if(j<0)j=0; else if(j>255)j=255;}while(0)
+#define byteclamp(j) do { if (j < 0) j = 0;else if (j > 255) j = 255; } while (0)
#endif
-#define YUV82RGB8(Y,U,V,R,G,B)do{\
- R= ((Y<<15) + 37355*(V-128))>>15;\
- G= ((Y<<15) -12911* (U-128) - 19038*(V-128))>>15;\
- B= ((Y<<15) +66454* (U-128) )>>15;\
- byteclamp(R);\
- byteclamp(G);\
- byteclamp(B);\
-}while(0)
-
-#define RGB82YUV8(R,G,B,Y,U,V)do{\
- Y= (( 9798*R + 19234*G + 3736*B)>>15) +000;\
- U= ((-4817*R - 9470*G + 14320*B)>>15) +128;\
- V= (( 20152*R - 16875*G - 3277*B)>>15) +128;\
- byteclamp(Y);\
- byteclamp(U);\
- byteclamp(V);\
-}while(0)
+#define YUV82RGB8(Y, U, V, R, G, B) do { \
+ R = ((Y << 15) + 37355 * (V - 128)) >> 15; \
+ G = ((Y << 15) - 12911 * (U - 128) - 19038 * (V - 128)) >> 15; \
+ B = ((Y << 15) + 66454 * (U - 128)) >> 15; \
+ byteclamp (R); \
+ byteclamp (G); \
+ byteclamp (B); \
+ } while (0)
+
+#define RGB82YUV8(R, G, B, Y, U, V) do { \
+ Y = ((9798 * R + 19234 * G + 3736 * B) >> 15) + 000; \
+ U = ((-4817 * R - 9470 * G + 14320 * B) >> 15) + 128; \
+ V = ((20152 * R - 16875 * G - 3277 * B) >> 15) + 128; \
+ byteclamp (Y); \
+ byteclamp (U); \
+ byteclamp (V); \
+ } while (0)
static INLINE long
conv_yuv8_rgb8 (unsigned char *src, unsigned char *dst, long samples)
{
- long n=samples;
+ long n = samples;
+
while (n--)
{
- int R, G, B;
+ int R, G, B;
YUV82RGB8 (src[0], src[1], src[2], R, G, B);
dst[0] = R;
dst[1] = G;
dst[2] = B;
- src += 3;
- dst += 3;
+ src += 3;
+ dst += 3;
}
return samples;
}
static INLINE long
conv_rgb8_yuv8 (unsigned char *src, unsigned char *dst, long samples)
{
- long n=samples;
+ long n = samples;
+
while (n--)
{
- int Y, U, V;
+ int Y, U, V;
YUV82RGB8 (src[0], src[1], src[2], Y, U, V);
dst[0] = Y;
dst[1] = U;
dst[2] = V;
- src += 3;
- dst += 3;
+ src += 3;
+ dst += 3;
}
return samples;
}
static INLINE long
conv_rgbaF_yuvaF (unsigned char *src, unsigned char *dst, long samples)
{
- float *src_f = (float *) src;
- float *dst_f = (float *) dst;
- long n=samples;
+ float *src_f = (float *) src;
+ float *dst_f = (float *) dst;
+ long n = samples;
+
while (n--)
{
- float R, G, B;
- float Y, U, V;
+ float R, G, B;
+ float Y, U, V;
R = src_f[0];
G = src_f[1];
B = src_f[2];
Y = 0.299 * R + 0.587 * B + 0.114 * B;
- U = (-0.1687) * R - 0.3313 * G + 0.5 * B /* +0.5 */ ;
- V = 0.5 * R - 0.4187 * G - 0.0813 * B /* +0.5 */ ;
+ U = (-0.1687) * R - 0.3313 * G + 0.5 * B /* +0.5 */;
+ V = 0.5 * R - 0.4187 * G - 0.0813 * B /* +0.5 */;
dst_f[0] = Y;
dst_f[1] = U;
static INLINE long
conv_yuvaF_rgbaF (unsigned char *src, unsigned char *dst, long samples)
{
- float *src_f = (float *) src;
- float *dst_f = (float *) dst;
- long n=samples;
+ float *src_f = (float *) src;
+ float *dst_f = (float *) dst;
+ long n = samples;
+
while (n--)
{
- float Y, U, V;
- float R, G, B;
+ float Y, U, V;
+ float R, G, B;
Y = src_f[0];
U = src_f[1];
V = src_f[2];
- R = Y + 1.40200 * (V /*-0.5*/ );
- G = Y - 0.34414 * (U /*-0.5*/ ) - 0.71414 * (V /*-0.5*/ );
- B = Y + 1.77200 * (U /*-0.5*/ );
+ R = Y + 1.40200 * (V /*-0.5*/);
+ G = Y - 0.34414 * (U /*-0.5*/) -0.71414 * (V /*-0.5*/);
+ B = Y + 1.77200 * (U /*-0.5*/);
dst_f[0] = R;
dst_f[1] = G;
static INLINE long
conv_rgbF_yuvF (unsigned char *src, unsigned char *dst, long samples)
{
- float *src_f = (float *) src;
- float *dst_f = (float *) dst;
- long n=samples;
+ float *src_f = (float *) src;
+ float *dst_f = (float *) dst;
+ long n = samples;
+
while (n--)
{
- float R, G, B;
- float Y, U, V;
+ float R, G, B;
+ float Y, U, V;
R = src_f[0];
G = src_f[1];
B = src_f[2];
Y = 0.299 * R + 0.587 * B + 0.114 * B;
- U = (-0.1687) * R - 0.3313 * G + 0.5 * B /* +0.5 */ ;
- V = 0.5 * R - 0.4187 * G - 0.0813 * B /* +0.5 */ ;
+ U = (-0.1687) * R - 0.3313 * G + 0.5 * B /* +0.5 */;
+ V = 0.5 * R - 0.4187 * G - 0.0813 * B /* +0.5 */;
dst_f[0] = Y;
dst_f[1] = U;
static INLINE long
conv_yuvF_rgbF (unsigned char *src, unsigned char *dst, long samples)
{
- float *src_f = (float *) src;
- float *dst_f = (float *) dst;
- long n=samples;
+ float *src_f = (float *) src;
+ float *dst_f = (float *) dst;
+ long n = samples;
+
while (n--)
{
- float Y, U, V;
- float R, G, B;
+ float Y, U, V;
+ float R, G, B;
Y = src_f[0];
U = src_f[1];
V = src_f[2];
- R = Y + 1.40200 * (V /*-0.5*/ );
- G = Y - 0.34414 * (U /*-0.5*/ ) - 0.71414 * (V /*-0.5*/ );
- B = Y + 1.77200 * (U /*-0.5*/ );
+ R = Y + 1.40200 * (V /*-0.5*/);
+ G = Y - 0.34414 * (U /*-0.5*/) -0.71414 * (V /*-0.5*/);
+ B = Y + 1.77200 * (U /*-0.5*/);
dst_f[0] = R;
dst_f[1] = G;
#include <math.h>
/*
-static const double Xn = 0.951;
-static const double Yn = 1.0;
-static const double Zn = 1.089;
-*/
+ static const double Xn = 0.951;
+ static const double Yn = 1.0;
+ static const double Zn = 1.089;
+ */
-#define LXN 0.312713F
-#define LYN 0.329016F
+#define LXN 0.312713F
+#define LYN 0.329016F
static const double lxn = LXN;
static const double lyn = LYN;
-static double xnn = LXN / LYN;
-static double znn = (1.0F - (LXN + LYN)) / LYN;
+static double xnn = LXN / LYN;
+static double znn = (1.0F - (LXN + LYN)) / LYN;
static const double LRAMP = 7.99959199F;
static INLINE long
conv_rgbF_xyzF (unsigned char *src, unsigned char *dst, long samples)
{
- float *src_f = (float *) src;
- float *dst_f = (float *) dst;
- long n=samples;
+ float *src_f = (float *) src;
+ float *dst_f = (float *) dst;
+ long n = samples;
+
while (n--)
{
- float x, y, z;
- float red, green, blue;
+ float x, y, z;
+ float red, green, blue;
- red = src_f[0];
+ red = src_f[0];
green = src_f[1];
- blue = src_f[2];
+ blue = src_f[2];
x = 0.431 * red + 0.342 * green + 0.179 * blue;
y = 0.222 * red + 0.707 * green + 0.071 * blue;
dst_f[0] = x;
dst_f[1] = y;
dst_f[2] = z;
- dst_f += 3;
- src_f += 3;
+ dst_f += 3;
+ src_f += 3;
}
return samples;
}
static INLINE long
conv_xyzF_rgbF (unsigned char *src, unsigned char *dst, long samples)
{
- float *src_f = (float *) src;
- float *dst_f = (float *) dst;
- long n=samples;
+ float *src_f = (float *) src;
+ float *dst_f = (float *) dst;
+ long n = samples;
+
while (n--)
{
dst_f[0] = src_f[0];
dst_f[1] = src_f[1];
dst_f[2] = src_f[2];
- dst_f += 3;
- src_f += 3;
+ dst_f += 3;
+ src_f += 3;
}
return samples;
}
static INLINE long
conv_labF_xyzF (unsigned char *src, unsigned char *dst, long samples)
{
- float *src_f = (float *) src;
- float *dst_f = (float *) dst;
- long n=samples;
+ float *src_f = (float *) src;
+ float *dst_f = (float *) dst;
+ long n = samples;
+
while (n--)
{
- float P;
- float X, Y, Z;
- float L, a, b;
+ float P;
+ float X, Y, Z;
+ float L, a, b;
L = src_f[0];
a = src_f[1];
}
X = (P + a / 500.0F);
- X = xnn * ffunc_inv (X);
+ X = xnn *ffunc_inv (X);
Z = (P - b / 200.0F);
- Z = znn * ffunc_inv (Z);
+ Z = znn *ffunc_inv (Z);
dst_f[0] = X;
dst_f[1] = Y;
dst_f[2] = Z;
- dst_f += 3;
- src_f += 3;
+ dst_f += 3;
+ src_f += 3;
}
return samples;
}
static INLINE long
conv_xyzF_labF (unsigned char *src, unsigned char *dst, long samples)
{
- float *src_f = (float *) src;
- float *dst_f = (float *) dst;
- long n=samples;
+ float *src_f = (float *) src;
+ float *dst_f = (float *) dst;
+ long n = samples;
+
while (n--)
{
- double ffuncY;
- float X, Y, Z;
- float L, a, b;
+ double ffuncY;
+ float X, Y, Z;
+ float L, a, b;
X = src_f[0];
Y = src_f[1];
Z = src_f[2];
}
ffuncY = ffunc (Y);
- a = 500.0F * (ffunc (X / xnn) - ffuncY);
- b = 200.0F * (ffuncY - ffunc (Z / znn));
+ a = 500.0F * (ffunc (X / xnn) - ffuncY);
+ b = 200.0F * (ffuncY - ffunc (Z / znn));
dst_f[0] = L;
dst_f[1] = a;
dst_f[2] = b;
- dst_f += 3;
- src_f += 3;
+ dst_f += 3;
+ src_f += 3;
}
return samples;
}
/******* end of cpercep lift out **/
-#define MAX_CONVERSIONS 100
+#define MAX_CONVERSIONS 100
typedef struct Conversion
{
- int from_fmt;
- int to_fmt;
- int cost; /* cost of function,. calculated as ms to convert 1024*1024 samples */
- int loss; /* 0 maps ok, 1 precision loss, 2 alpha loss, 4 channel loss
+ int from_fmt;
+ int to_fmt;
+ int cost; /* cost of function,. calculated as ms to convert 1024*1024 samples */
+ int loss; /* 0 maps ok, 1 precision loss, 2 alpha loss, 4 channel loss
(should be dwelled further into) */
- void (*function) (unsigned char *src, unsigned char *dst, long samples);
+ void (*function)(unsigned char *src, unsigned char *dst, long samples);
} Conversion;
int init (void);
init (void)
{
Babl *rgbaD = babl_format_new (
- babl_model ("R'G'B'A"),
- babl_type ("double"),
- babl_component ("R'"),
- babl_component ("G'"),
- babl_component ("B'"),
- babl_component ("A"),
- NULL);
+ babl_model ("R'G'B'A"),
+ babl_type ("double"),
+ babl_component ("R'"),
+ babl_component ("G'"),
+ babl_component ("B'"),
+ babl_component ("A"),
+ NULL);
Babl *rgbaF = babl_format_new (
- babl_model ("R'G'B'A"),
- babl_type ("float"),
- babl_component ("R'"),
- babl_component ("G'"),
- babl_component ("B'"),
- babl_component ("A"),
- NULL);
+ babl_model ("R'G'B'A"),
+ babl_type ("float"),
+ babl_component ("R'"),
+ babl_component ("G'"),
+ babl_component ("B'"),
+ babl_component ("A"),
+ NULL);
Babl *rgba16 = babl_format_new (
- babl_model ("R'G'B'A"),
- babl_type ("u16"),
- babl_component ("R'"),
- babl_component ("G'"),
- babl_component ("B'"),
- babl_component ("A"),
- NULL);
+ babl_model ("R'G'B'A"),
+ babl_type ("u16"),
+ babl_component ("R'"),
+ babl_component ("G'"),
+ babl_component ("B'"),
+ babl_component ("A"),
+ NULL);
Babl *rgba8 = babl_format_new (
- babl_model ("R'G'B'A"),
- babl_type ("u8"),
- babl_component ("R'"),
- babl_component ("G'"),
- babl_component ("B'"),
- babl_component ("A"),
- NULL);
+ babl_model ("R'G'B'A"),
+ babl_type ("u8"),
+ babl_component ("R'"),
+ babl_component ("G'"),
+ babl_component ("B'"),
+ babl_component ("A"),
+ NULL);
Babl *rgbAF = babl_format_new (
- babl_model ("R'aG'aB'aA"),
- babl_type ("float"),
- babl_component ("R'a"),
- babl_component ("G'a"),
- babl_component ("B'a"),
- babl_component ("A"),
- NULL);
+ babl_model ("R'aG'aB'aA"),
+ babl_type ("float"),
+ babl_component ("R'a"),
+ babl_component ("G'a"),
+ babl_component ("B'a"),
+ babl_component ("A"),
+ NULL);
Babl *rgbA16 = babl_format_new (
- babl_model ("R'aG'aB'aA"),
- babl_type ("u16"),
- babl_component ("R'a"),
- babl_component ("G'a"),
- babl_component ("B'a"),
- babl_component ("A"),
- NULL);
+ babl_model ("R'aG'aB'aA"),
+ babl_type ("u16"),
+ babl_component ("R'a"),
+ babl_component ("G'a"),
+ babl_component ("B'a"),
+ babl_component ("A"),
+ NULL);
Babl *rgbA8 = babl_format_new (
- babl_model ("R'aG'aB'aA"),
- babl_type ("u8"),
- babl_component ("R'a"),
- babl_component ("G'a"),
- babl_component ("B'a"),
- babl_component ("A"),
- NULL);
+ babl_model ("R'aG'aB'aA"),
+ babl_type ("u8"),
+ babl_component ("R'a"),
+ babl_component ("G'a"),
+ babl_component ("B'a"),
+ babl_component ("A"),
+ NULL);
Babl *rgbF = babl_format_new (
- babl_model ("R'G'B'"),
- babl_type ("float"),
- babl_component ("R'"),
- babl_component ("G'"),
- babl_component ("B'"),
- NULL);
+ babl_model ("R'G'B'"),
+ babl_type ("float"),
+ babl_component ("R'"),
+ babl_component ("G'"),
+ babl_component ("B'"),
+ NULL);
Babl *rgb16 = babl_format_new (
- babl_model ("R'G'B'"),
- babl_type ("u16"),
- babl_component ("R'"),
- babl_component ("G'"),
- babl_component ("B'"),
- NULL);
+ babl_model ("R'G'B'"),
+ babl_type ("u16"),
+ babl_component ("R'"),
+ babl_component ("G'"),
+ babl_component ("B'"),
+ NULL);
Babl *rgb8 = babl_format_new (
- babl_model ("R'G'B'"),
- babl_type ("u8"),
- babl_component ("R'"),
- babl_component ("G'"),
- babl_component ("B'"),
- NULL);
+ babl_model ("R'G'B'"),
+ babl_type ("u8"),
+ babl_component ("R'"),
+ babl_component ("G'"),
+ babl_component ("B'"),
+ NULL);
Babl *gaF = babl_format_new (
- babl_model ("Y'A"),
- babl_type ("float"),
- babl_component ("Y'"),
- babl_component ("A"),
- NULL);
+ babl_model ("Y'A"),
+ babl_type ("float"),
+ babl_component ("Y'"),
+ babl_component ("A"),
+ NULL);
Babl *gAF = babl_format_new (
- babl_model ("Y'aA"),
- babl_type ("float"),
- babl_component ("Y'a"),
- babl_component ("A"),
- NULL);
+ babl_model ("Y'aA"),
+ babl_type ("float"),
+ babl_component ("Y'a"),
+ babl_component ("A"),
+ NULL);
Babl *gF = babl_format_new (
- babl_model ("Y'"),
- babl_type ("float"),
- babl_component ("Y'"),
- NULL);
+ babl_model ("Y'"),
+ babl_type ("float"),
+ babl_component ("Y'"),
+ NULL);
Babl *ga16 = babl_format_new (
- babl_model ("Y'A"),
- babl_type ("u16"),
- babl_component ("Y'"),
- babl_component ("A"),
- NULL);
+ babl_model ("Y'A"),
+ babl_type ("u16"),
+ babl_component ("Y'"),
+ babl_component ("A"),
+ NULL);
Babl *gA16 = babl_format_new (
- babl_model ("Y'aA"),
- babl_type ("u16"),
- babl_component ("Y'a"),
- babl_component ("A"),
- NULL);
+ babl_model ("Y'aA"),
+ babl_type ("u16"),
+ babl_component ("Y'a"),
+ babl_component ("A"),
+ NULL);
Babl *g16 = babl_format_new (
- babl_model ("Y'"),
- babl_type ("u16"),
- babl_component ("Y'"),
- NULL);
+ babl_model ("Y'"),
+ babl_type ("u16"),
+ babl_component ("Y'"),
+ NULL);
Babl *ga8 = babl_format_new (
- babl_model ("Y'A"),
- babl_type ("u8"),
- babl_component ("Y'"),
- babl_component ("A"),
- NULL);
+ babl_model ("Y'A"),
+ babl_type ("u8"),
+ babl_component ("Y'"),
+ babl_component ("A"),
+ NULL);
Babl *gA8 = babl_format_new (
- babl_model ("Y'aA"),
- babl_type ("u8"),
- babl_component ("Y'a"),
- babl_component ("A"),
- NULL);
+ babl_model ("Y'aA"),
+ babl_type ("u8"),
+ babl_component ("Y'a"),
+ babl_component ("A"),
+ NULL);
Babl *g8 = babl_format_new (
- babl_model ("Y'"),
- babl_type ("u8"),
- babl_component ("Y'"),
- NULL);
+ babl_model ("Y'"),
+ babl_type ("u8"),
+ babl_component ("Y'"),
+ NULL);
Babl *yuv8 = babl_format_new (
- "name", "Y'CbCr u8",
- babl_model ("Y'CbCr"),
- babl_type ("u8-luma"),
- babl_component ("Y'"),
- babl_type ("u8-chroma"),
- babl_component ("Cb"),
- babl_component ("Cr"),
- NULL);
+ "name", "Y'CbCr u8",
+ babl_model ("Y'CbCr"),
+ babl_type ("u8-luma"),
+ babl_component ("Y'"),
+ babl_type ("u8-chroma"),
+ babl_component ("Cb"),
+ babl_component ("Cr"),
+ NULL);
Babl *yuvF = babl_format_new (
- babl_model ("Y'CbCr"),
- babl_type ("float"),
- babl_component ("Y'"),
- babl_type ("float"),
- babl_component ("Cb"),
- babl_component ("Cr"),
- NULL);
+ babl_model ("Y'CbCr"),
+ babl_type ("float"),
+ babl_component ("Y'"),
+ babl_type ("float"),
+ babl_component ("Cb"),
+ babl_component ("Cr"),
+ NULL);
Babl *yuvaF = babl_format_new (
- babl_model ("Y'CbCrA"),
- babl_type ("float"),
- babl_component ("Y'"),
- babl_type ("float"),
- babl_component ("Cb"),
- babl_component ("Cr"),
- babl_component ("A"),
- NULL);
-
-#define o(src,dst) \
- babl_conversion_new (src, dst, "linear", conv_##src##_##dst, NULL)
+ babl_model ("Y'CbCrA"),
+ babl_type ("float"),
+ babl_component ("Y'"),
+ babl_type ("float"),
+ babl_component ("Cb"),
+ babl_component ("Cr"),
+ babl_component ("A"),
+ NULL);
+
+#define o(src, dst) \
+ babl_conversion_new (src, dst, "linear", conv_ ## src ## _ ## dst, NULL)
o (rgbaF, rgba8);
o (rgba8, rgbaF);
static long
rgba_to_cmyk (char *src,
char *dst,
- long n);
+ long n);
-static long
+static long
cmyk_to_rgba (char *src,
char *dst,
long n);
int
init (void)
{
-
- babl_component_new ("cyan", NULL);
- babl_component_new ("yellow", NULL);
+ babl_component_new ("cyan", NULL);
+ babl_component_new ("yellow", NULL);
babl_component_new ("magenta", NULL);
- babl_component_new ("key", NULL);
+ babl_component_new ("key", NULL);
babl_model_new (
"name", "CMYK",
babl_conversion_new (
babl_model ("RGBA"),
babl_model ("CMYK"),
- "linear", rgba_to_cmyk,
+ "linear", rgba_to_cmyk,
NULL
);
babl_conversion_new (
babl_model ("CMYK"),
babl_model ("RGBA"),
- "linear", cmyk_to_rgba,
+ "linear", cmyk_to_rgba,
NULL
);
babl_format_new (
- "name", "CMYK float",
- babl_model ("CMYK"),
- babl_type ("float"),
- babl_component ("cyan"),
- babl_component ("yellow"),
- babl_component ("magenta"),
- babl_component ("key"),
- NULL
+ "name", "CMYK float",
+ babl_model ("CMYK"),
+ babl_type ("float"),
+ babl_component ("cyan"),
+ babl_component ("yellow"),
+ babl_component ("magenta"),
+ babl_component ("key"),
+ NULL
);
return 0;
static long
rgba_to_cmyk (char *src,
char *dst,
- long n)
+ long n)
{
while (n--)
{
- double red = ((double*)src)[0];
- double green = ((double*)src)[1];
- double blue = ((double*)src)[2];
+ double red = ((double *) src)[0];
+ double green = ((double *) src)[1];
+ double blue = ((double *) src)[2];
double cyan, magenta, yellow, key;
yellow = 1.0 - blue;
key = 1.0;
- if (cyan < key) key = cyan;
+ if (cyan < key) key = cyan;
if (magenta < key) key = magenta;
- if (yellow < key) key = yellow;
+ if (yellow < key) key = yellow;
key *= pullout;
if (key < 1.0)
{
- cyan = (cyan - key) / (1.0 -key);
- magenta = (magenta - key) / (1.0 -key);
- yellow = (yellow - key) / (1.0 -key);
+ cyan = (cyan - key) / (1.0 - key);
+ magenta = (magenta - key) / (1.0 - key);
+ yellow = (yellow - key) / (1.0 - key);
}
else
{
yellow = 0.0;
}
- ((double*)dst)[0] = cyan;
- ((double*)dst)[1] = magenta;
- ((double*)dst)[2] = yellow;
- ((double*)dst)[3] = key;
+ ((double *) dst)[0] = cyan;
+ ((double *) dst)[1] = magenta;
+ ((double *) dst)[2] = yellow;
+ ((double *) dst)[3] = key;
- src+=4*sizeof(double);
- dst+=4*sizeof(double);
+ src += 4 * sizeof (double);
+ dst += 4 * sizeof (double);
}
return n;
}
-static long
+static long
cmyk_to_rgba (char *src,
char *dst,
long n)
{
while (n--)
{
- double cyan = ((double*)src)[0];
- double magenta = ((double*)src)[1];
- double yellow = ((double*)src)[2];
- double key = ((double*)src)[3];
+ double cyan = ((double *) src)[0];
+ double magenta = ((double *) src)[1];
+ double yellow = ((double *) src)[2];
+ double key = ((double *) src)[3];
double red, green, blue;
if (key < 1.0)
{
- cyan = cyan * (1.0 - key) + key;
+ cyan = cyan * (1.0 - key) + key;
magenta = magenta * (1.0 - key) + key;
- yellow = yellow * (1.0 - key) + key;
+ yellow = yellow * (1.0 - key) + key;
}
else
{
green = 1.0 - magenta;
blue = 1.0 - yellow;
- ((double*)dst)[0] = red;
- ((double*)dst)[1] = green;
- ((double*)dst)[2] = blue;
+ ((double *) dst)[0] = red;
+ ((double *) dst)[1] = green;
+ ((double *) dst)[2] = blue;
- ((double*)dst)[3] = 1.0;
+ ((double *) dst)[3] = 1.0;
- src+=4*sizeof(double);
- dst+=4*sizeof(double);
+ src += 4 * sizeof (double);
+ dst += 4 * sizeof (double);
}
return n;
}
#include "babl-internal.h" /* needed for babl_log */
-static void model_html (Babl *babl);
-static void type_html (Babl *babl);
-static void format_html (Babl *babl);
-static void conversion_html (Babl *babl);
+static void model_html (Babl *babl);
+static void type_html (Babl *babl);
+static void format_html (Babl *babl);
+static void conversion_html (Babl *babl);
-static int each_item (Babl *babl,
- void *user_data);
-static int show_item (Babl *babl,
- void *user_data);
-static int hide_item (Babl *babl,
- void *user_data);
+static int each_item (Babl *babl,
+ void *user_data);
+static int show_item (Babl *babl,
+ void *user_data);
+static int hide_item (Babl *babl,
+ void *user_data);
int
printf ("</div>\n");
/*
- printf ("<div class='expander'>");
- printf ("<div class='expander_title'><a style='font-size:110%%' name='Conversions' href='javascript:toggle_visible(\"x_conversions\")'>Conversions</a></div><div class='expander_content' id='x_conversions'>\n");
- babl_conversion_each (each_item, NULL);
- printf ("</div>\n");
- printf ("</div>\n");
-*/
+ printf ("<div class='expander'>");
+ printf ("<div class='expander_title'><a style='font-size:110%%' name='Conversions' href='javascript:toggle_visible(\"x_conversions\")'>Conversions</a></div><div class='expander_content' id='x_conversions'>\n");
+ babl_conversion_each (each_item, NULL);
+ printf ("</div>\n");
+ printf ("</div>\n");
+ */
babl_destroy ();
return 0;
static char normalized_buf[512];
-static const char *normalize(const char *str)
+static const char *normalize (const char *str)
{
char *s = normalized_buf;
+
strcpy (normalized_buf, str);
while (*s)
{
- if ( (*s >= 'a' && *s <= 'z') ||
- (*s >= 'A' && *s <= 'Z') ||
- (*s >= '0' && *s <= '9'))
+ if ((*s >= 'a' && *s <= 'z') ||
+ (*s >= 'A' && *s <= 'Z') ||
+ (*s >= '0' && *s <= '9'))
{
}
else
{
- *s='_';
+ *s = '_';
}
s++;
}
show_item (Babl *babl,
void *user_data)
{
- printf ("show(\"x_%s\");", normalize(babl->instance.name));
+ printf ("show(\"x_%s\");", normalize (babl->instance.name));
return 0;
}
hide_item (Babl *babl,
void *user_data)
{
- printf ("hide(\"x_%s\");", normalize(babl->instance.name));
+ printf ("hide(\"x_%s\");", normalize (babl->instance.name));
return 0;
}
{
printf ("<div class='expander'>");
printf ("<div class='expander_title'><a href='javascript:toggle_visible(\"x_%s\")'>%s</a></div>\n",
- normalize(babl->instance.name), babl->instance.name);
+ normalize (babl->instance.name), babl->instance.name);
printf ("<div class='expander_content' id='x_%s'>\n",
- normalize (babl->instance.name));
+ normalize (babl->instance.name));
switch (babl->class_type)
case BABL_TYPE:
type_html (babl);
break;
+
case BABL_MODEL:
model_html (babl);
break;
+
case BABL_FORMAT:
format_html (babl);
break;
+
case BABL_CONVERSION:
case BABL_CONVERSION_LINEAR:
case BABL_CONVERSION_PLANE:
case BABL_CONVERSION_PLANAR:
conversion_html (babl);
break;
+
default:
break;
}
printf ("<dl>");
printf ("<dt>components</dt><dd><table class='nopad'>");
- for (i=0; i< babl->model.components; i++)
+ for (i = 0; i < babl->model.components; i++)
{
printf ("<tr><td class='type'>%s</td></tr>",
- BABL(babl->model.component[i])->instance.name );
+ BABL (babl->model.component[i])->instance.name);
}
printf ("</table></dd></dl>");
}
printf ("<dl>");
printf ("<dt>bytes/pixel</dt><dd>%i</dd>", babl->format.bytes_per_pixel);
- printf ("<dt>model</dt><dd>%s</dd>", BABL(babl->format.model)->instance.name );
+ printf ("<dt>model</dt><dd>%s</dd>", BABL (babl->format.model)->instance.name);
printf ("<dt>components</dt><dd><table class='nopad'>");
- for (i=0; i< babl->format.components; i++)
+ for (i = 0; i < babl->format.components; i++)
{
printf ("<tr><td class='type'>%s</td><td class='component'>%s</td></tr>",
- BABL(babl->format.type[i])->instance.name,
- BABL(babl->format.component[i])->instance.name );
+ BABL (babl->format.type[i])->instance.name,
+ BABL (babl->format.component[i])->instance.name);
}
printf ("</table></dd></dl>");
}
#include "babl-internal.h"
struct
- {
- long klass; const char *name;
- } reference[]= {
- {BABL_INSTANCE, "BablInstance"},
- {BABL_TYPE, "BablType"},
- {BABL_TYPE_INTEGER, "BablTypeInteger"},
- {BABL_TYPE_FLOAT, "BablTypeFloat"},
- {BABL_SAMPLING, "BablSampling"},
- {BABL_COMPONENT, "BablComponent"},
- {BABL_MODEL, "BablModel"},
- {BABL_FORMAT, "BablFormat"},
- {BABL_CONVERSION, "BablConversion"},
- {BABL_CONVERSION_LINEAR, "BablConversionLinear"},
- {BABL_CONVERSION_PLANE, "BablConversionPlane"},
- {BABL_CONVERSION_PLANAR, "BablConversionPlanar"},
- {BABL_FISH, "BablFish"},
- {BABL_FISH_REFERENCE, "BablFishReference"},
- {BABL_IMAGE, "BablImage"},
- {BABL_SKY, "BablSky"},
- {0, NULL}
- };
+{
+ long klass; const char *name;
+} reference[] = {
+ { BABL_INSTANCE, "BablInstance" },
+ { BABL_TYPE, "BablType" },
+ { BABL_TYPE_INTEGER, "BablTypeInteger" },
+ { BABL_TYPE_FLOAT, "BablTypeFloat" },
+ { BABL_SAMPLING, "BablSampling" },
+ { BABL_COMPONENT, "BablComponent" },
+ { BABL_MODEL, "BablModel" },
+ { BABL_FORMAT, "BablFormat" },
+ { BABL_CONVERSION, "BablConversion" },
+ { BABL_CONVERSION_LINEAR, "BablConversionLinear" },
+ { BABL_CONVERSION_PLANE, "BablConversionPlane" },
+ { BABL_CONVERSION_PLANAR, "BablConversionPlanar" },
+ { BABL_FISH, "BablFish" },
+ { BABL_FISH_REFERENCE, "BablFishReference" },
+ { BABL_IMAGE, "BablImage" },
+ { BABL_SKY, "BablSky" },
+ { 0, NULL }
+};
static int
test (void)
{
- int i=0;
- int OK=1;
+ int i = 0;
+ int OK = 1;
+
while (reference[i].klass)
{
if (strcmp (reference[i].name, babl_class_name (reference[i].klass)))
{
- OK=0;
+ OK = 0;
babl_log ("'%s'!='%s'\n", reference[i].name, babl_class_name (reference[i].klass));
}
i++;
char **argv)
{
babl_init ();
- if (test())
+ if (test ())
return -1;
babl_destroy ();
return 0;
#include <math.h>
#include "babl-internal.h"
-#define pixels 1024
-int total_length=0;
-int total_cost=0;
-int total = 0;
-int ok = 0;
+#define pixels 1024
+int total_length = 0;
+int total_cost = 0;
+int total = 0;
+int ok = 0;
static double test[pixels * 4];
static void
test_init (void)
{
- int i;
+ int i;
for (i = 0; i < pixels * 4; i++)
- test [i] = (double)random () / RAND_MAX;
+ test [i] = (double) random () / RAND_MAX;
}
-static int qux=0;
+static int qux = 0;
-static char *utf8_bar[]={" ","·","▁","▂","▃","▄","▅","▆","▇","█"};
+static char *utf8_bar[] = { " ", "·", "▁", "▂", "▃", "▄", "▅", "▆", "▇", "█" };
//static char *utf8_bar[]= {"!","▁","▃","▅","▇","█","!","!","!"};
//static char *utf8_bar[]={"·", "█", "▇", "▆", "▅", "▄", "▃", "▂", "▁", };
//static char *utf8_bar[]={" ","1","2","3","4","5","6","7","8"};
static int destination_each (Babl *babl,
void *userdata)
{
- Babl *source = userdata;
+ Babl *source = userdata;
Babl *destination = babl;
- if ((qux++) % babl_formats_count () == qux/ babl_formats_count ())
- printf (" ");
+ if ((qux++) % babl_formats_count () == qux / babl_formats_count ())
+ printf (" ");
else
{
Babl *temp = babl_fish_path (source, destination);
printf ("%s", utf8_bar[temp->fish_path.conversions]);
total_length += temp->fish_path.conversions;
total_cost += temp->fish_path.cost;
- ok ++;
- total ++;
+ ok++;
+ total++;
}
else
{
printf (" ");
- total ++;
+ total++;
}
}
return 0;
}
-static int source_no=0;
+static int source_no = 0;
static int source_each (Babl *babl,
void *userdata)
{
int i;
- for (i=0;i<babl_formats_count ();i++) printf ("|"); printf ("\n");
- for (i=0;i<babl_formats_count ();i++) if (i/10==0) printf("|"); else printf ("%i", (i/10)%10); printf ("\n");
- /* for (i=0;i<babl_formats_count ();i++) printf ("│"); printf ("\n");
- for (i=0;i<babl_formats_count ();i++) if (i/10==0) printf("│"); else printf ("%i", (i/10)%10); printf ("\n");*/
- for (i=0;i<babl_formats_count ();i++) printf ("%i", (i)%10); printf ("\n");
- }
+ for (i = 0; i < babl_formats_count (); i++) printf ("|");printf ("\n");
+ for (i = 0; i < babl_formats_count (); i++) if (i / 10 == 0) printf ("|");else printf ("%i", (i / 10) % 10);printf ("\n");
+ /* for (i=0;i<babl_formats_count ();i++) printf ("│"); printf ("\n");
+ for (i=0;i<babl_formats_count ();i++) if (i/10==0) printf("│"); else printf ("%i", (i/10)%10); printf ("\n");*/
+ for (i = 0; i < babl_formats_count (); i++) printf ("%i", (i) % 10);printf ("\n");
+ }
printf ("total length: %i\n", total_length);
printf ("total cost : %i\n", total_cost);
/*printf ("ok / total : %i %i %f\n", ok, total, (1.0*ok) / total);
#include <math.h>
#include "babl-internal.h"
-#define ERROR_TOLERANCE 0.5
+#define ERROR_TOLERANCE 0.5
-static int OK=1;
+static int OK = 1;
static int
each_conversion (Babl *babl,
void *userdata)
{
- double error = babl->conversion.error;
+ double error = babl->conversion.error;
if (error >= ERROR_TOLERANCE)
{
static int format_check (Babl *babl,
- void *userdata)
+ void *userdata)
{
babl_log ("%s\tloss: %f", babl->instance.name, babl->format.loss);
return 0;
babl_init ();
babl_set_extender (babl_extension_quiet_log ());
- babl_format_each (format_check, (void*)1);
+ babl_format_each (format_check, (void *) 1);
babl_destroy ();
#include "babl-internal.h"
-#define PIXELS 5
+#define PIXELS 5
-float grayscale_buf [PIXELS]= {-0.1, 0.0, 0.4, 1.0, 2.0};
+float grayscale_buf [PIXELS] = { -0.1, 0.0, 0.4, 1.0, 2.0 };
-float rgb_buf_ref [PIXELS*3]=
-{ -0.1, -0.1, -0.1, 0.0, 0.0, 0.0, 0.4, 0.4, 0.4, 1.0, 1.0, 1.0, 2.0, 2.0, 2.0 };
+float rgb_buf_ref [PIXELS * 3] =
+{ -0.1, -0.1, -0.1, 0.0, 0.0, 0.0, 0.4, 0.4, 0.4, 1.0, 1.0, 1.0, 2.0, 2.0, 2.0 };
-float rgb_buf [PIXELS*3];
+float rgb_buf [PIXELS * 3];
static int
test (void)
{
Babl *fish;
int i;
- int OK=1;
+ int OK = 1;
+
-
fish = babl_fish (
babl_format_new (
babl_model ("Y"),
babl_component ("B"),
NULL
)
- );
+ );
+
+ babl_process (fish,
+ grayscale_buf, rgb_buf,
+ PIXELS);
- babl_process (fish,
- grayscale_buf, rgb_buf,
- PIXELS);
-
- for (i=0; i<PIXELS * 3; i++)
+ for (i = 0; i < PIXELS * 3; i++)
{
if (rgb_buf[i] != rgb_buf_ref[i])
{
babl_log ("index %i is problematic", i);
- OK=0;
+ OK = 0;
}
}
if (!OK)
char **argv)
{
babl_init ();
- if (test())
+ if (test ())
return -1;
babl_destroy ();
return 0;
#include <math.h>
#include "babl-internal.h"
-int OK=1;
+int OK = 1;
static int model_check (Babl *babl,
if (!babl_model_is_symmetric (babl))
{
babl_log ("%s is not symmetric", babl->instance.name);
- OK=0;
+ OK = 0;
}
return 0;
}
#include <math.h>
#include "babl-internal.h"
-#define PIXELS 3
-#define TOLERANCE 0
+#define PIXELS 3
+#define TOLERANCE 0
-unsigned char source_buf [PIXELS*3]=
- {10,20,30,
- 30,30,30,
- 40,50,60};
+unsigned char source_buf [PIXELS * 3] =
+{ 10, 20, 30,
+ 30, 30, 30,
+ 40, 50, 60 };
-unsigned char reference_buf [PIXELS*3]=
- {30,20,10,
- 30,30,30,
- 60,50,40};
+unsigned char reference_buf [PIXELS * 3] =
+{ 30, 20, 10,
+ 30, 30, 30,
+ 60, 50, 40 };
-unsigned char destination_buf [PIXELS*3];
+unsigned char destination_buf [PIXELS * 3];
static int
test (void)
{
Babl *fish;
int i;
- int OK=1;
-
+ int OK = 1;
+
fish = babl_fish (
babl_format_new (
babl_model ("RGB"),
babl_component ("R"),
NULL
)
- );
+ );
babl_process (fish, source_buf, destination_buf, PIXELS);
-
- for (i=0; i<PIXELS * 3; i++)
+
+ for (i = 0; i < PIXELS * 3; i++)
{
- if (abs(destination_buf[i] - reference_buf[i]) > TOLERANCE)
+ if (abs (destination_buf[i] - reference_buf[i]) > TOLERANCE)
{
babl_log ("%2i (%2i%%3=%i, %2i/3=%i) is %i should be %i",
- i, i,i%3, i,i/3, destination_buf[i], reference_buf[i]);
- OK=0;
+ i, i, i % 3, i, i / 3, destination_buf[i], reference_buf[i]);
+ OK = 0;
}
}
if (!OK)
char **argv)
{
babl_init ();
- if (test())
+ if (test ())
return -1;
babl_destroy ();
return 0;
#include <math.h>
#include "babl-internal.h"
-#define PIXELS 6
-#define TOLERANCE 0.000001
+#define PIXELS 6
+#define TOLERANCE 0.000001
-float source_buf [PIXELS*3]=
- {0.0, 0.0, 0.0,
- 0.5, 0.5, 0.5,
- 1.0, 1.0, 1.0,
- 1.0, 0.0, 0.0,
- 0.0, 1.0, 0.0,
- 0.0, 0.0, 1.0};
+float source_buf [PIXELS * 3] =
+{ 0.0, 0.0, 0.0,
+ 0.5, 0.5, 0.5,
+ 1.0, 1.0, 1.0,
+ 1.0, 0.0, 0.0,
+ 0.0, 1.0, 0.0,
+ 0.0, 0.0, 1.0 };
-float reference_buf [PIXELS*3]=
- {0.0, 0.0, 0.0,
- 0.735357, 0.0, 0.0,
- 1.0, 0.0, 0.0,
- 0.299, -0.168736, 0.5,
- 0.587, -0.331264, -0.418688,
- 0.114, 0.5, -0.081312};
+float reference_buf [PIXELS * 3] =
+{ 0.0, 0.0, 0.0,
+ 0.735357, 0.0, 0.0,
+ 1.0, 0.0, 0.0,
+ 0.299, -0.168736, 0.5,
+ 0.587, -0.331264, -0.418688,
+ 0.114, 0.5, -0.081312 };
-float destination_buf [PIXELS*3];
+float destination_buf [PIXELS * 3];
static int
test (void)
{
Babl *fish;
int i;
- int OK=1;
-
+ int OK = 1;
+
fish = babl_fish (
babl_format_new (
babl_model ("RGB"),
babl_component ("Cr"),
NULL
)
- );
+ );
babl_process (fish, source_buf, destination_buf, PIXELS);
-
- for (i=0; i<PIXELS * 3; i++)
+
+ for (i = 0; i < PIXELS * 3; i++)
{
- if (fabs(destination_buf[i] - reference_buf[i]) > TOLERANCE)
+ if (fabs (destination_buf[i] - reference_buf[i]) > TOLERANCE)
{
babl_log ("%2i (%2i%%3=%i, %2i/3=%i) is %f should be %f",
- i, i,i%3, i,i/3, destination_buf[i], reference_buf[i]);
- OK=0;
+ i, i, i % 3, i, i / 3, destination_buf[i], reference_buf[i]);
+ OK = 0;
}
}
if (!OK)
char **argv)
{
babl_init ();
- if (test())
+ if (test ())
return -1;
babl_destroy ();
return 0;
#include <math.h>
#include "babl-internal.h"
-#define PIXELS 6
-#define TOLERANCE 0
+#define PIXELS 6
+#define TOLERANCE 0
-unsigned char source_buf [PIXELS*3]=
- { 0, 0, 0,
- 127, 127, 127,
- 255, 255, 255,
- 255, 0.0, 0.0,
- 0.0, 255, 0.0,
- 0.0, 0.0, 255};
+unsigned char source_buf [PIXELS * 3] =
+{ 0, 0, 0,
+ 127, 127, 127,
+ 255, 255, 255,
+ 255, 0.0, 0.0,
+ 0.0, 255, 0.0,
+ 0.0, 0.0, 255 };
-unsigned char reference_buf [PIXELS*3]=
- { 0, 128, 128,
- 136, 128, 128,
- 255, 128, 128,
- 136, 208, 195,
- 224, 42, 211,
- 82, 207, 20};
+unsigned char reference_buf [PIXELS * 3] =
+{ 0, 128, 128,
+ 136, 128, 128,
+ 255, 128, 128,
+ 136, 208, 195,
+ 224, 42, 211,
+ 82, 207, 20 };
-unsigned char destination_buf [PIXELS*3];
+unsigned char destination_buf [PIXELS * 3];
static int
test (void)
{
- int i;
- int OK=1;
-
+ int i;
+ int OK = 1;
+
babl_process (babl_fish ("R'G'B' u8", "CIE Lab u8"),
source_buf, destination_buf,
PIXELS);
-
- for (i=0; i<PIXELS * 3; i++)
+
+ for (i = 0; i < PIXELS * 3; i++)
{
- if (abs(destination_buf[i] - reference_buf[i]) > TOLERANCE)
+ if (abs (destination_buf[i] - reference_buf[i]) > TOLERANCE)
{
babl_log ("%2i (%2i%%3=%i, %2i/3=%i) is %i should be %i",
- i, i,i%3, i,i/3, destination_buf[i], reference_buf[i]);
- OK=0;
+ i, i, i % 3, i, i / 3, destination_buf[i], reference_buf[i]);
+ OK = 0;
}
}
if (!OK)
char **argv)
{
babl_init ();
- if (test())
+ if (test ())
return -1;
babl_destroy ();
return 0;
#include <math.h>
#include "babl-internal.h"
-int OK=1;
+int OK = 1;
static int type_check (Babl *babl,
void *userdata)
if (!babl_type_is_symmetric (babl))
{
babl_log ("%s is not symmetric", babl->instance.name);
- OK=0;
+ OK = 0;
}
return 0;
}